Class: Brainstem::DSL::HashBlockField

Inherits:
BlockField show all
Defined in:
lib/brainstem/dsl/hash_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

#executable?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/brainstem/dsl/hash_block_field.rb', line 22

def executable?
  (options.keys & EXECUTABLE_OPTIONS).present?
end

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



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

def run_on(model, context, helper_instance = Object.new)
  evaluated_model = nil
  evaluated_model = evaluate_value_on(model, context, helper_instance) if executable?

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

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

  result
end