Class: LHS::Data
- Inherits:
-
Object
- Object
- LHS::Data
- Defined in:
- lib/lhs/data.rb,
lib/lhs/concerns/data/json.rb,
lib/lhs/concerns/data/to_hash.rb,
lib/lhs/concerns/data/equality.rb
Overview
Data provides functionalities to accesses information
Defined Under Namespace
Modules: Equality, Json, ToHash
Instance Attribute Summary collapse
-
#_endpoint ⇒ Object
prevent clashing with attributes of underlying data.
-
#_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.
-
#_record ⇒ Object
prevent clashing with attributes of underlying data.
-
#_request ⇒ Object
prevent clashing with attributes of underlying data.
Instance Method Summary collapse
- #_root ⇒ Object
- #class ⇒ Object
- #collection? ⇒ Boolean
-
#initialize(input, parent = nil, record = nil, request = nil, endpoint = nil) ⇒ Data
constructor
A new instance of Data.
- #item? ⇒ Boolean
-
#merge_raw!(data) ⇒ Object
merging data e.g.
- #parent ⇒ Object
- #root_item? ⇒ Boolean
Methods included from Inspect
Methods included from Json
Methods included from Equality
Constructor Details
#initialize(input, parent = nil, record = nil, request = nil, endpoint = nil) ⇒ Data
Returns a new instance of Data.
16 17 18 19 20 21 22 23 |
# File 'lib/lhs/data.rb', line 16 def initialize(input, parent = nil, record = nil, request = nil, endpoint = nil) self._raw = raw_from_input(input) self._parent = parent self._record = record self._proxy = proxy_from_input(input) self._request = request self._endpoint = endpoint end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
70 71 72 |
# File 'lib/lhs/data.rb', line 70 def method_missing(name, *args, &block) _proxy.send(name, *args, &block) end |
Instance Attribute Details
#_endpoint ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _endpoint @_endpoint end |
#_parent ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _parent @_parent end |
#_proxy ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _proxy @_proxy end |
#_raw ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _raw @_raw end |
#_record ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _record @_record end |
#_request ⇒ Object
prevent clashing with attributes of underlying data
14 15 16 |
# File 'lib/lhs/data.rb', line 14 def _request @_request end |
Instance Method Details
#_root ⇒ Object
32 33 34 35 36 |
# File 'lib/lhs/data.rb', line 32 def _root root = self root = root._parent while root && root._parent root end |
#class ⇒ Object
46 47 48 |
# File 'lib/lhs/data.rb', line 46 def class _root._record end |
#collection? ⇒ Boolean
60 61 62 |
# File 'lib/lhs/data.rb', line 60 def collection? _proxy.is_a? LHS::Collection end |
#merge_raw!(data) ⇒ Object
merging data e.g. when loading remote data via link
27 28 29 30 |
# File 'lib/lhs/data.rb', line 27 def merge_raw!(data) return false if data.blank? || !data._raw.is_a?(Hash) _raw.merge! data._raw end |
#parent ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/lhs/data.rb', line 38 def parent if _parent && _parent._record _parent._record.new(_parent, false) else _parent end end |
#root_item? ⇒ Boolean
56 57 58 |
# File 'lib/lhs/data.rb', line 56 def root_item? root_item == self end |