Class: Brainstem::DSL::ArrayBlockField

Inherits:
BlockField show all
Defined in:
lib/brainstem/dsl/array_block_field.rb

Instance Attribute Summary

Attributes inherited from BlockField

#configuration

Attributes inherited from Field

#conditionals, #name, #options, #type

Instance Method Summary collapse

Methods inherited from BlockField

#[], #evaluate_value_on, for, #initialize, #use_parent_value?

Methods inherited from Field

#conditional?, #conditionals_match?, #description, #evaluate_value_on, #initialize, #method_name, #optional?, #optioned?, #presentable?

Methods included from Concerns::Lookup

#key_for_lookup, #run_on_with_lookup

Constructor Details

This class inherits a constructor from Brainstem::DSL::BlockField

Instance Method Details

#run_on(model, context, helper_instance = Object.new) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/brainstem/dsl/array_block_field.rb', line 7

def run_on(model, context, helper_instance = Object.new)
  evaluated_models = evaluate_value_on(model, context, helper_instance)

  evaluated_models.map do |evaluated_model|
    result = {}

    configuration.each do |field_name, field|
      next unless field.presentable?(model, context)

      model_for_field = use_parent_value?(field) ? evaluated_model : model
      result[field_name] = field.run_on(model_for_field, context, context[:helper_instance])
    end

    result
  end
end