Class: Representable::Binding

Inherits:
Object
  • Object
show all
Extended by:
Uber::Delegates
Includes:
Deprecatable, EvaluateOption, Factories
Defined in:
lib/representable/binding.rb

Overview

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.

Direct Known Subclasses

Hash::Binding, Object::Binding, XML::Binding

Defined Under Namespace

Modules: Collection, Deprecatable, EvaluateOption, Factories Classes: FragmentNotFound, Map

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Factories

#collect_for, #default_parse_fragment_functions, #default_parse_init_functions, #default_post_functions, #default_render_fragment_functions, #default_render_init_functions, #parse_functions, #pipeline_for, #render_functions

Methods included from EvaluateOption

#evaluate_option

Methods included from Deprecatable

#compile_fragment, #uncompile_fragment

Constructor Details

#initialize(definition) ⇒ Binding

Returns a new instance of Binding.



13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#cached_representerObject

Returns the value of attribute cached_representer.



64
65
66
# File 'lib/representable/binding.rb', line 64

def cached_representer
  @cached_representer
end

#getterObject (readonly)

Returns the value of attribute getter.



22
23
24
# File 'lib/representable/binding.rb', line 22

def getter
  @getter
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/representable/binding.rb', line 22

def name
  @name
end

#setterObject (readonly)

Returns the value of attribute setter.



22
23
24
# File 'lib/representable/binding.rb', line 22

def setter
  @setter
end

Class Method Details

.build(definition) ⇒ Object



9
10
11
# File 'lib/representable/binding.rb', line 9

def self.build(definition)
  build_for(definition)
end

Instance Method Details

#[](name) ⇒ Object



51
52
53
# File 'lib/representable/binding.rb', line 51

def [](name)
  @definition[name]
end

#default_for(value) ⇒ Object



59
60
61
62
# 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) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/representable/binding.rb', line 55

def skipable_empty_value?(value)
  value.nil? and not self[:render_nil]
end