class Brainstem::DSL::BlockField

Attributes

configuration[R]

Public Class Methods

for(name, type, options, parent_field = nil) click to toggle source
# File lib/brainstem/dsl/block_field.rb, line 34
def self.for(name, type, options, parent_field = nil)
  case type.to_s
    when 'array'
      DSL::ArrayBlockField.new(name, type, options, parent_field)
    when 'hash'
      DSL::HashBlockField.new(name, type, options, parent_field)
    else
      raise "Unknown Brainstem Block Field type encountered: #{type}"
  end
end
new(name, type, options, parent_field = nil) click to toggle source
Calls superclass method
# File lib/brainstem/dsl/block_field.rb, line 11
def initialize(name, type, options, parent_field = nil)
  super(name, type, options)
  @parent_field = parent_field
end

Public Instance Methods

[](key) click to toggle source
# File lib/brainstem/dsl/block_field.rb, line 26
def [](key)
  configuration[key]
end
evaluate_value_on(model, context, helper_instance = Object.new) click to toggle source
# File lib/brainstem/dsl/block_field.rb, line 45
def evaluate_value_on(model, context, helper_instance = Object.new)
  if options[:lookup]
    run_on_with_lookup(model, context, helper_instance)
  elsif options[:dynamic]
    proc = options[:dynamic]
    if proc.arity == 1
      helper_instance.instance_exec(model, &proc)
    else
      helper_instance.instance_exec(&proc)
    end
  elsif options[:via]
    model.send(options[:via])
  else
    raise "Block field #{name} can only be evaluated if :dynamic, :lookup, :via options are specified."
  end
end
run_on(model, context, helper_instance = Object.new) click to toggle source
# File lib/brainstem/dsl/block_field.rb, line 30
def run_on(model, context, helper_instance = Object.new)
  raise NotImplementedError.new("Override this method in a sub class")
end
use_parent_value?(field) click to toggle source
# File lib/brainstem/dsl/block_field.rb, line 62
def use_parent_value?(field)
  return true unless field.options.has_key?(:use_parent_value)

  field.options[:use_parent_value]
end