class Representable::Binding

The Binding provides methods to read/write the fragment for one property.

Actually parsing the fragment from the document happens in Binding#read, everything after that is generic.

Attributes

cached_representer[RW]
getter[R]
name[R]
setter[R]

Public Class Methods

build(definition) click to toggle source
# File lib/representable/binding.rb, line 9
def self.build(definition)
  build_for(definition)
end
new(definition) click to toggle source
# File lib/representable/binding.rb, line 13
def initialize(definition)
  @definition       = definition
  @name             = @definition.name
  @getter           = @definition.getter
  @setter           = @definition.setter

  setup_exec_context!
end

Public Instance Methods

[](name) click to toggle source
# File lib/representable/binding.rb, line 51
def [](name)
  @definition[name]
end
default_for(value) click to toggle source
# File lib/representable/binding.rb, line 59
def default_for(value)
  return self[:default] if skipable_empty_value?(value)
  value
end
skipable_empty_value?(value) click to toggle source
# File lib/representable/binding.rb, line 55
def skipable_empty_value?(value)
  value.nil? and not self[:render_nil]
end

Private Instance Methods

exec_context(options) click to toggle source
# File lib/representable/binding.rb, line 77
def exec_context(options)
  @exec_context.(options)
end
parse_pipeline(input, options) click to toggle source
# File lib/representable/binding.rb, line 81
def parse_pipeline(input, options)
  @parse_pipeline ||= pipeline_for(:parse_pipeline, input, options) { Pipeline[*parse_functions] }
end
render_pipeline(input, options) click to toggle source
# File lib/representable/binding.rb, line 85
def render_pipeline(input, options)
  @render_pipeline ||= pipeline_for(:render_pipeline, input, options) { Pipeline[*render_functions] }
end
setup_exec_context!() click to toggle source
# File lib/representable/binding.rb, line 71
def setup_exec_context!
  @exec_context = ->(options) { options[:represented] }     unless self[:exec_context]
  @exec_context = ->(options) { self }                      if self[:exec_context] == :binding
  @exec_context = ->(options) { options[:decorator] }       if self[:exec_context] == :decorator
end