Class: Sqreen::BindingAccessor
- Inherits:
-
Object
- Object
- Sqreen::BindingAccessor
- Includes:
- Transforms
- Defined in:
- lib/sqreen/binding_accessor.rb,
lib/sqreen/binding_accessor/path_elem.rb,
lib/sqreen/binding_accessor/transforms.rb
Overview
the value located at the given binding
Defined Under Namespace
Modules: Transforms Classes: PathElem
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#final_transform ⇒ Object
readonly
Returns the value of attribute final_transform.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#transform_args ⇒ Object
readonly
Returns the value of attribute transform_args.
Instance Method Summary collapse
-
#access(binding, framework = nil, instance = nil, arguments = nil, cbdata = nil, last_return = nil) ⇒ Object
Access data from the expression.
- #eql?(other) ⇒ Boolean (also: #==)
-
#hash ⇒ Object
implement eql? and hash for uniq.
-
#initialize(expression, convert = false) ⇒ BindingAccessor
constructor
Expression to be accessed.
-
#resolve(*args) ⇒ Object
access and transform expression for the given binding.
Methods included from Transforms
#concat_keys_and_values, #flat_keys, #flat_values
Constructor Details
#initialize(expression, convert = false) ⇒ BindingAccessor
Expression to be accessed
21 22 23 24 25 26 27 28 |
# File 'lib/sqreen/binding_accessor.rb', line 21 def initialize(expression, convert = false) @transform_args = [] @final_transform = nil @expression = expression @path = [] @convert = convert parse(expression) end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
15 16 17 |
# File 'lib/sqreen/binding_accessor.rb', line 15 def expression @expression end |
#final_transform ⇒ Object
Returns the value of attribute final_transform.
15 16 17 |
# File 'lib/sqreen/binding_accessor.rb', line 15 def final_transform @final_transform end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/sqreen/binding_accessor.rb', line 15 def path @path end |
#transform_args ⇒ Object (readonly)
Returns the value of attribute transform_args.
15 16 17 |
# File 'lib/sqreen/binding_accessor.rb', line 15 def transform_args @transform_args end |
Instance Method Details
#access(binding, framework = nil, instance = nil, arguments = nil, cbdata = nil, last_return = nil) ⇒ Object
Access data from the expression
31 32 33 34 35 36 37 38 |
# File 'lib/sqreen/binding_accessor.rb', line 31 def access(binding, framework = nil, instance = nil, arguments = nil, cbdata = nil, last_return = nil) env = [framework, instance, arguments, cbdata, last_return] value = nil @path.each do |component| value = resolve_component(value, component, binding, env) end value end |
#eql?(other) ⇒ Boolean Also known as: ==
53 54 55 56 57 |
# File 'lib/sqreen/binding_accessor.rb', line 53 def eql?(other) self.class == other.class && expression == other.expression && @convert == other.instance_variable_get('@convert') end |
#hash ⇒ Object
implement eql? and hash for uniq
49 50 51 |
# File 'lib/sqreen/binding_accessor.rb', line 49 def hash expression.hash ^ @convert.hash end |
#resolve(*args) ⇒ Object
access and transform expression for the given binding
41 42 43 44 45 46 |
# File 'lib/sqreen/binding_accessor.rb', line 41 def resolve(*args) value = access(*args) value = transform(value) if @final_transform return convert(value) if @convert value end |