Skip to content

Commit

Permalink
Merge pull request #2 from dvla/feature/allow-field-creation-from-symbol
Browse files Browse the repository at this point in the history
Feature/allow field creation from symbol
  • Loading branch information
devonwhale authored Apr 9, 2024
2 parents 1ede14d + 07f40cb commit 419a2f6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/gem-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Ruby Build

on:
schedule:
- cron: '0 7 * * 1'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: [ '3.0', '3.1', '3.2' ]

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run checks
run: |
gem install bundler-audit
bundle-audit check --update
bundle exec rspec
- name: Report test failure
if: ${{ failure() }}
run: |
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an')
curl -H 'Content-Type: application/json' -d "{\"title\": \"${REPO_NAME} GitHub build failed.\",\"text\": \"Build **${BUILD_NUMBER}** on the main branch by ${COMMIT_AUTHOR} [GitHub Action](${ACTION_LINK}) | [Repo Branch](${BRANCH_LINK}) **Commit Message** ${COMMIT_MESSAGE}\",\"themeColor\": \"EA4300\"}" -s ${WEBHOOK_URL}
env:
REPO_NAME: "${{ github.event.repository.name }}"
BUILD_NUMBER: "${{ github.run_number }}"
ACTION_LINK: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
BRANCH_LINK: "${{ github.server_url }}/${{ github.repository }}"
WEBHOOK_URL: "${{ secrets.WEBHOOK_URL }}"
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
inherit_gem:
dvla-lint: ".rubocop.yml"
1 change: 1 addition & 0 deletions dvla-atlas.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'sorbet-runtime', '~> 0.5'

spec.add_development_dependency 'bundler-audit', '~> 0.9'
spec.add_development_dependency 'dvla-lint', '~> 1.7'
spec.add_development_dependency 'rspec', '~> 3.8'
spec.add_development_dependency 'sorbet', '~> 0.5'
spec.add_development_dependency 'tapioca', '~> 0.10'
Expand Down
10 changes: 5 additions & 5 deletions lib/dvla/atlas/artefacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Atlas
class Artefacts
extend T::Sig

sig { params(vargs: String, kwargs: T.untyped).void }
sig { params(vargs: T.any(String, Symbol), kwargs: T.untyped).void }
def define_fields(*vargs, **kwargs)
vargs.each do |attr|
initialise_fields(attr)
Expand All @@ -25,17 +25,17 @@ def define_fields(*vargs, **kwargs)
def initialise_fields(name)
# Create the history of the newly defined field. This will start out empty. There is no public way to set this so
# no need to expose it by defining a method.
instance_variable_set("@#{name}_history", [])
instance_variable_set(:"@#{name}_history", [])

# Create the getter for the new field, and ensure that it is run upon call if it is a proc.
define_singleton_method :"#{name}" do
value = instance_variable_get("@#{name}")
value = instance_variable_get(:"@#{name}")
value.respond_to?(:call) ? value.call : value
end

# Define a getter for the history of the new field
define_singleton_method :"#{name}_history" do
instance_variable_get("@#{name}_history")
instance_variable_get(:"@#{name}_history")
end

# Define the setter for the new field. This also pushes the current value of the field into the history unless
Expand All @@ -44,7 +44,7 @@ def initialise_fields(name)
define_singleton_method :"#{name}=" do |arg|
current_value = send(:"#{name}")
send(:"#{name}_history").push(current_value) unless send(:"#{name}_history").empty? && current_value.nil?
instance_variable_set("@#{name}", arg)
instance_variable_set(:"@#{name}", arg)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dvla/atlas/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module DVLA
module Atlas
VERSION = '1.0.0'.freeze
VERSION = '1.1.0'.freeze
end
end

0 comments on commit 419a2f6

Please sign in to comment.