Class: LHS::Data
- Inherits:
-
Object
- Object
- LHS::Data
- Includes:
- Json
- Defined in:
- lib/lhs/data.rb,
lib/lhs/concerns/data/json.rb
Overview
Data provides functionalities to accesses information
Defined Under Namespace
Modules: Json
Instance Attribute Summary collapse
-
#_parent ⇒ Object
prevent clashing with attributes of underlying data.
-
#_proxy ⇒ Object
prevent clashing with attributes of underlying data.
-
#_raw ⇒ Object
prevent clashing with attributes of underlying data.
-
#_request ⇒ Object
prevent clashing with attributes of underlying data.
-
#_service ⇒ Object
prevent clashing with attributes of underlying data.
Instance Method Summary collapse
- #_root ⇒ Object
- #class ⇒ Object
-
#initialize(input, parent = nil, service = nil, request = nil) ⇒ Data
constructor
A new instance of Data.
-
#merge!(data) ⇒ Object
merging data e.g.
Methods included from Json
Constructor Details
#initialize(input, parent = nil, service = nil, request = nil) ⇒ Data
Returns a new instance of Data.
11 12 13 14 15 16 17 |
# File 'lib/lhs/data.rb', line 11 def initialize(input, parent = nil, service = nil, request = nil) self._raw = raw_from_input(input) self._proxy = proxy_from_input(input) self._service = service self._parent = parent self._request = request end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
Use existing mapping to provide data or forward to proxy
40 41 42 43 44 45 46 |
# File 'lib/lhs/data.rb', line 40 def method_missing(name, *args, &block) if root_item? && mapping = _root._service.instance.mapping[name] self.instance_exec(&mapping) else _proxy.send(name, *args, &block) end end |
Instance Attribute Details
#_parent ⇒ Object
prevent clashing with attributes of underlying data
9 10 11 |
# File 'lib/lhs/data.rb', line 9 def _parent @_parent end |
#_proxy ⇒ Object
prevent clashing with attributes of underlying data
9 10 11 |
# File 'lib/lhs/data.rb', line 9 def _proxy @_proxy end |
#_raw ⇒ Object
prevent clashing with attributes of underlying data
9 10 11 |
# File 'lib/lhs/data.rb', line 9 def _raw @_raw end |
#_request ⇒ Object
prevent clashing with attributes of underlying data
9 10 11 |
# File 'lib/lhs/data.rb', line 9 def _request @_request end |
#_service ⇒ Object
prevent clashing with attributes of underlying data
9 10 11 |
# File 'lib/lhs/data.rb', line 9 def _service @_service end |
Instance Method Details
#_root ⇒ Object
26 27 28 29 30 |
# File 'lib/lhs/data.rb', line 26 def _root root = self root = root._parent while root && root._parent root end |
#class ⇒ Object
32 33 34 |
# File 'lib/lhs/data.rb', line 32 def class _root._service end |
#merge!(data) ⇒ Object
merging data e.g. when loading remote data via link
21 22 23 24 |
# File 'lib/lhs/data.rb', line 21 def merge!(data) return false unless data._raw.is_a?(Hash) _raw.merge! data._raw end |