Skip to content

Commit af35d4a

Browse files
author
James McCarthy
committed
Change as: proc to be run in the context of the entity.
1 parent 3790bc2 commit af35d4a

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/grape_entity/exposure/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def attr_path(entity, options)
104104
end
105105

106106
def key(entity = nil)
107-
@key.respond_to?(:call) ? @key.call(entity) : @key
107+
@key.respond_to?(:call) ? entity.exec_with_object(@options, &@key) : @key
108108
end
109109

110110
def with_attr_path(entity, options)

spec/grape_entity/exposure_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
end
3434

3535
it 'returns the result if :as is a proc' do
36-
fresh_class.expose :name, as: -> (entity) { entity.object.name.reverse }
36+
fresh_class.expose :name, as: -> { object.name.reverse }
3737
expect(subject.key(entity)).to eq(model.name.reverse)
3838
end
3939
end

0 commit comments

Comments
 (0)