From 8eca9a2e5419c3b5be45d5c7eae3fbc84a36c433 Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Tue, 22 Oct 2024 18:06:27 -0400 Subject: [PATCH] Clean up field/association attributes Signed-off-by: Jordan Hollinger --- lib/blueprinter/v2/association.rb | 3 +-- lib/blueprinter/v2/dsl.rb | 8 ++------ lib/blueprinter/v2/field.rb | 3 +-- spec/v2/fields_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/blueprinter/v2/association.rb b/lib/blueprinter/v2/association.rb index c091d0ea..e0c5cac5 100644 --- a/lib/blueprinter/v2/association.rb +++ b/lib/blueprinter/v2/association.rb @@ -7,9 +7,8 @@ module V2 :blueprint, :legacy_view, :from, - :if_cond, :value_proc, - :custom_options, + :options, keyword_init: true ) end diff --git a/lib/blueprinter/v2/dsl.rb b/lib/blueprinter/v2/dsl.rb index b759d1e4..096169f4 100644 --- a/lib/blueprinter/v2/dsl.rb +++ b/lib/blueprinter/v2/dsl.rb @@ -43,7 +43,6 @@ 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] # @@ -51,9 +50,8 @@ 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 @@ -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] # @@ -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 diff --git a/lib/blueprinter/v2/field.rb b/lib/blueprinter/v2/field.rb index f9cc419a..58e8891e 100644 --- a/lib/blueprinter/v2/field.rb +++ b/lib/blueprinter/v2/field.rb @@ -5,9 +5,8 @@ module V2 Field = Struct.new( :name, :from, - :if_cond, :value_proc, - :custom_options, + :options, keyword_init: true ) end diff --git a/spec/v2/fields_spec.rb b/spec/v2/fields_spec.rb index 00dc8a8a..fc83ef42 100644 --- a/spec/v2/fields_spec.rb +++ b/spec/v2/fields_spec.rb @@ -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 @@ -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"