Module: DataBindings::Unbound
- Included in:
- Adapters::Native::NativeAdapter, Adapters::Ruby::RubyArrayAdapter, Adapters::Ruby::RubyObjectAdapter
- Defined in:
- lib/data_bindings/unbound.rb
Overview
Module that handles unbound objects
Instance Attribute Summary collapse
-
#binding ⇒ Object
readonly
Returns the value of attribute binding.
-
#binding_name ⇒ Object
readonly
Returns the value of attribute binding_name.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #bind(name = nil, opts = nil, &blk) ⇒ Object
- #bind!(name = nil, &blk) ⇒ Object
- #bind_array(type = nil, opts = nil, &blk) ⇒ Object
- #binding_class ⇒ Object
- #convert_target ⇒ Object
- #hash? ⇒ Boolean
- #to_native ⇒ Object
- #type ⇒ Object
- #update_binding(name, &blk) ⇒ Object
Instance Attribute Details
#binding ⇒ Object (readonly)
Returns the value of attribute binding.
5 6 7 |
# File 'lib/data_bindings/unbound.rb', line 5 def binding @binding end |
#binding_name ⇒ Object (readonly)
Returns the value of attribute binding_name.
5 6 7 |
# File 'lib/data_bindings/unbound.rb', line 5 def binding_name @binding_name end |
Instance Method Details
#array? ⇒ Boolean
46 47 48 |
# File 'lib/data_bindings/unbound.rb', line 46 def array? type == :array end |
#bind(name = nil, opts = nil, &blk) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/data_bindings/unbound.rb', line 15 def bind(name = nil, opts = nil, &blk) if name.is_a?(Unbound) update_binding(name.binding_name, &name.binding) else name, opts = nil, name if name.is_a?(Hash) && opts.nil? raise if name.nil? && blk.nil? update_binding(name, &blk) end binding_class.new(@generator, @array, self, name, opts, &@binding) end |
#bind!(name = nil, &blk) ⇒ Object
7 8 9 |
# File 'lib/data_bindings/unbound.rb', line 7 def bind!(name = nil, &blk) bind(name, &blk).valid! end |
#bind_array(type = nil, opts = nil, &blk) ⇒ Object
26 27 28 29 30 |
# File 'lib/data_bindings/unbound.rb', line 26 def bind_array(type = nil, opts = nil, &blk) type, opts = nil, type if type.is_a?(Hash) && opts.nil? update_binding([], &blk) binding_class.new(@generator, @array, self, nil, opts, &blk) end |
#binding_class ⇒ Object
69 70 71 72 73 74 |
# File 'lib/data_bindings/unbound.rb', line 69 def binding_class case type when :array then @generator.binding_class(Bound::BoundArray) when :hash then @generator.binding_class(Bound::BoundObject) end end |
#convert_target ⇒ Object
11 12 13 |
# File 'lib/data_bindings/unbound.rb', line 11 def convert_target bind { copy_source } end |
#hash? ⇒ Boolean
42 43 44 |
# File 'lib/data_bindings/unbound.rb', line 42 def hash? type == :hash end |
#to_native ⇒ Object
50 51 52 53 54 |
# File 'lib/data_bindings/unbound.rb', line 50 def to_native array? ? map{ |m| m.respond_to?(:to_native) ? m.to_native : m } : OpenStruct.new(inject({}) {|h, (k, v)| v = @generator.from_ruby(v); h[k] = (v.respond_to?(:to_native) ? v.to_native : v); h}) end |
#type ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/data_bindings/unbound.rb', line 32 def type if self.is_a?(Array) :array elsif self.is_a?(Hash) :hash else raise end end |
#update_binding(name, &blk) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/data_bindings/unbound.rb', line 56 def update_binding(name, &blk) if name.is_a?(Array) n = name.at(0) @array = true blk = proc { all_elements n } name = nil else @array = false end @binding = @generator.get_type(name) || blk || raise(UnknownBindingError, "Unknown binding #{name.inspect}") @name = name end |