Skip to content

Commit

Permalink
Fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Jul 28, 2020
1 parent 2fe9df8 commit 71d3f60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
16 changes: 14 additions & 2 deletions lib/nose/model/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,20 @@ def self.add_field_method(child_class)
method_name = child_class.name.sub(method_regex, '\1')
EntityDSL.send :define_method, method_name,
(proc do |*args|
send(:instance_variable_get, :@entity).send \
:<<, child_class.new(*args)
entity = send :instance_variable_get, :@entity

# XXX This is necessary since passing a hash of
# keyword arguments as the last argument is
# now deprecated
if args.last.is_a? Hash
hash_args = args.last
args.pop
else
hash_args = {}
end

field = child_class.new(*args, **hash_args)
entity.send :<<, field
end)
end
private_class_method :add_field_method
Expand Down
2 changes: 1 addition & 1 deletion spec/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module NoSE
end

HasOne 'foo', 'bars',
'Bar' => 'Foo'
{'Bar' => 'Foo'}
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/support/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module NoSE
end) * 1000

HasOne 'User', 'Tweets',
'Tweet' => 'User'
{'Tweet' => 'User'}

HasOne 'Favourite', 'Favourited',
'User' => 'Tweet'
{'User' => 'Tweet'}

HasOne 'Link', 'Tweets',
'Tweet' => 'Link'
{'Tweet' => 'Link'}
end
end
# rubocop:enable Lint/Void
Expand Down

0 comments on commit 71d3f60

Please sign in to comment.