Skip to content

Commit fb7fb0c

Browse files
committed
Pass options as keywords during block extraction
Signed-off-by: Tyler Hunt <tyler@tylerhunt.com>
1 parent 463357b commit fb7fb0c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/blueprinter/extractors/block_extractor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Blueprinter
66
# @api private
77
class BlockExtractor < Extractor
88
def extract(_field_name, object, local_options, options = {})
9-
options[:block].call(object, local_options)
9+
options[:block].call(object, **local_options)
1010
end
1111
end
1212
end

spec/integrations/shared/base_render_examples.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,20 @@ def self.if_method(_field_name, _object, _local_opts)
516516
it('returns json with values derived from options') { should eq(result) }
517517
end
518518

519+
context 'Given ::render with options with keyword field option' do
520+
subject { blueprint.render(obj, vehicle: vehicle) }
521+
let(:result) { '{"id":' + obj_id + ',"vehicle_make":"Super Car"}' }
522+
let(:blueprint) do
523+
Class.new(Blueprinter::Base) do
524+
identifier :id
525+
field :vehicle_make do |_obj, vehicle:, **|
526+
"#{vehicle[:make]}"
527+
end
528+
end
529+
end
530+
it('returns json with values derived from options') { should eq(result) }
531+
end
532+
519533
context 'Given ::render in a nested included view, original view is accessible in options' do
520534
let(:blueprint) do
521535
Class.new(Blueprinter::Base) do

0 commit comments

Comments
 (0)