Class: LHS::Data

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Json

#as_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

#_parentObject

prevent clashing with attributes of underlying data



9
10
11
# File 'lib/lhs/data.rb', line 9

def _parent
  @_parent
end

#_proxyObject

prevent clashing with attributes of underlying data



9
10
11
# File 'lib/lhs/data.rb', line 9

def _proxy
  @_proxy
end

#_rawObject

prevent clashing with attributes of underlying data



9
10
11
# File 'lib/lhs/data.rb', line 9

def _raw
  @_raw
end

#_requestObject

prevent clashing with attributes of underlying data



9
10
11
# File 'lib/lhs/data.rb', line 9

def _request
  @_request
end

#_serviceObject

prevent clashing with attributes of underlying data



9
10
11
# File 'lib/lhs/data.rb', line 9

def _service
  @_service
end

Instance Method Details

#_rootObject



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

#classObject



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