Skip to content

Commit

Permalink
feature: generate alias_method
Browse files Browse the repository at this point in the history
  • Loading branch information
vadshalamov committed Jun 1, 2016
1 parent 8768c09 commit ddfa482
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/treasury/fields/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def extract_object(params)

def extract_attribute_name(name)
class_attribute :attribute_name, instance_writer: false
singleton_class.send(:alias_method, "extract_#{name}".to_sym, :extract_object)

self.attribute_name = name
end
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/treasury/fields/extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
it { expect { class_with_extractor.extract_object(object: {another_object: 1}) }.to raise_error(ArgumentError) }
end

context 'when call alias method' do
it { expect(class_with_extractor.extract_user(object: {user_id: 1})).to eq 1 }
end

it 'return object id' do
user = double(:user, id: 1)

Expand Down

0 comments on commit ddfa482

Please sign in to comment.