Skip to content

Commit

Permalink
Clean up field/association attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Hollinger <[email protected]>
  • Loading branch information
jhollinger committed Oct 22, 2024
1 parent 023d1fc commit 8eca9a2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
3 changes: 1 addition & 2 deletions lib/blueprinter/v2/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ module V2
:blueprint,
:legacy_view,
:from,
:if_cond,
:value_proc,
:custom_options,
:options,
keyword_init: true
)
end
Expand Down
8 changes: 2 additions & 6 deletions lib/blueprinter/v2/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,15 @@ def use(*names)
#
# @param name [Symbol] Name of the field
# @param from [Symbol] Optionally specify a different method to call to get the value for "name"
# @param if [Proc] Only include this field if the Proc evaluates to truthy
# @yield [TODO] Generate the value from the block
# @return [Blueprinter::V2::Field]
#
def field(name, from: name, **options, &definition)
fields[name.to_sym] = Field.new(
name: name,
from: from,
if_cond: options.delete(:if),
value_proc: definition,
custom_options: options
options: options.dup
)
end

Expand All @@ -64,7 +62,6 @@ def field(name, from: name, **options, &definition)
# @param blueprint [Class|Proc] Blueprint class to use, or one defined with a Proc
# @param view [Symbol] Only for use with legacy (not V2) blueprints
# @param from [Symbol] Optionally specify a different method to call to get the value for "name"
# @param if [Proc] Only include this association if the Proc evaluates to truthy
# @yield [TODO] Generate the value from the block
# @return [Blueprinter::V2::Association]
#
Expand All @@ -76,9 +73,8 @@ def association(name, blueprint, from: name, view: nil, **options, &definition)
blueprint: blueprint,
legacy_view: view,
from: from,
if_cond: options.delete(:if),
value_proc: definition,
custom_options: options
options: options.dup
)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/blueprinter/v2/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ module V2
Field = Struct.new(
:name,
:from,
:if_cond,
:value_proc,
:custom_options,
:options,
keyword_init: true
)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/v2/fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
expect(ref.fields[:name].from).to eq :name
expect(ref.fields[:description].name).to eq :description
expect(ref.fields[:description].from).to eq :desc
expect(ref.fields[:description].if_cond.class.name).to eq "Proc"
expect(ref.fields[:description].options[:if].class.name).to eq "Proc"
expect(ref.fields[:foo].name).to eq :foo
expect(ref.fields[:foo].value_proc.class.name).to eq "Proc"
end
Expand All @@ -39,7 +39,7 @@
expect(ref.associations[:widgets].name).to eq :widgets
expect(ref.associations[:widgets].from).to eq :foo
expect(ref.associations[:widgets].blueprint).to eq widget_blueprint
expect(ref.associations[:widgets].if_cond.class.name).to eq "Proc"
expect(ref.associations[:widgets].options[:if].class.name).to eq "Proc"
expect(ref.associations[:foo].name).to eq :foo
expect(ref.associations[:foo].blueprint).to eq widget_blueprint
expect(ref.associations[:foo].value_proc.class.name).to eq "Proc"
Expand Down

0 comments on commit 8eca9a2

Please sign in to comment.