Class: DHS::Data
- Inherits:
-
Object
- Object
- DHS::Data
- Defined in:
- lib/dhs/data.rb,
lib/dhs/concerns/data/json.rb,
lib/dhs/concerns/data/extend.rb,
lib/dhs/concerns/data/becomes.rb,
lib/dhs/concerns/data/to_hash.rb,
lib/dhs/concerns/data/equality.rb
Overview
Data provides functionalities to accesses information
Defined Under Namespace
Modules: Becomes, Equality, Extend, 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
Returns the value of attribute _raw.
-
#_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
-
#unwrap(usecase) ⇒ Object
Unwraps data for certain use cases like items_created_key for CREATE, UPDATED etc.
Methods included from Inspect
Methods included from Json
Methods included from Extend
Methods included from Equality
Methods included from Becomes
Constructor Details
#initialize(input, parent = nil, record = nil, request = nil, endpoint = nil) ⇒ Data
Returns a new instance of Data.
29 30 31 32 33 34 35 36 37 |
# File 'lib/dhs/data.rb', line 29 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 preserve_input_requests!(input) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **keyword_args, &block) ⇒ Object (protected)
93 94 95 |
# File 'lib/dhs/data.rb', line 93 def method_missing(name, *args, **keyword_args, &block) _proxy.send(name, *args, **keyword_args, &block) end |
Instance Attribute Details
#_endpoint ⇒ Object
prevent clashing with attributes of underlying data
26 27 28 |
# File 'lib/dhs/data.rb', line 26 def _endpoint @_endpoint end |
#_parent ⇒ Object
prevent clashing with attributes of underlying data
26 27 28 |
# File 'lib/dhs/data.rb', line 26 def _parent @_parent end |
#_proxy ⇒ Object
prevent clashing with attributes of underlying data
26 27 28 |
# File 'lib/dhs/data.rb', line 26 def _proxy @_proxy end |
#_raw ⇒ Object
Returns the value of attribute _raw.
27 28 29 |
# File 'lib/dhs/data.rb', line 27 def _raw @_raw end |
#_record ⇒ Object
prevent clashing with attributes of underlying data
26 27 28 |
# File 'lib/dhs/data.rb', line 26 def _record @_record end |
#_request ⇒ Object
prevent clashing with attributes of underlying data
26 27 28 |
# File 'lib/dhs/data.rb', line 26 def _request @_request end |
Instance Method Details
#_root ⇒ Object
55 56 57 58 59 |
# File 'lib/dhs/data.rb', line 55 def _root root = self root = root._parent while root&._parent root end |
#class ⇒ Object
69 70 71 |
# File 'lib/dhs/data.rb', line 69 def class _record || _root._record end |
#collection? ⇒ Boolean
83 84 85 |
# File 'lib/dhs/data.rb', line 83 def collection? _proxy.is_a? DHS::Collection end |
#merge_raw!(data) ⇒ Object
merging data e.g. when loading remote data via link
41 42 43 44 |
# File 'lib/dhs/data.rb', line 41 def merge_raw!(data) return false if data.blank? || !data._raw.is_a?(Hash) _raw.merge! data._raw end |
#parent ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/dhs/data.rb', line 61 def parent if _parent&._record _parent._record.new(_parent, false) else _parent end end |
#root_item? ⇒ Boolean
79 80 81 |
# File 'lib/dhs/data.rb', line 79 def root_item? root_item == self end |
#unwrap(usecase) ⇒ Object
Unwraps data for certain use cases like items_created_key for CREATE, UPDATED etc. like item_key for GET etc.
49 50 51 52 53 |
# File 'lib/dhs/data.rb', line 49 def unwrap(usecase) nested_path = record.send(usecase) if record return DHS::Data.new(dig(*nested_path) || _raw, nil, self.class) if nested_path self end |