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 27
def self.build(definition)
  build_for(definition)
end
new(definition) click to toggle source
# File lib/representable/binding.rb, line 31
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 69
def [](name)
  @definition[name]
end
default_for(value) click to toggle source
# File lib/representable/binding.rb, line 77
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 73
def skipable_empty_value?(value)
  value.nil? and !(self[:render_nil])
end

Private Instance Methods

exec_context(options) click to toggle source
# File lib/representable/binding.rb, line 96
def exec_context(options)
  @exec_context.call(options)
end
parse_pipeline(input, options) click to toggle source
# File lib/representable/binding.rb, line 100
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 104
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 90
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