Class: LHS::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/lhs/proxy.rb

Overview

Proxy makes different kind of data accessible If href is present it also alows loading/reloading

Direct Known Subclasses

Collection, Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Proxy

Returns a new instance of Proxy.



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

def initialize(data)
  self._data = data
  self._loaded = false
end

Instance Attribute Details

#_dataObject

prevent clashing with attributes of underlying data



6
7
8
# File 'lib/lhs/proxy.rb', line 6

def _data
  @_data
end

#_loadedObject

prevent clashing with attributes of underlying data



6
7
8
# File 'lib/lhs/proxy.rb', line 6

def _loaded
  @_loaded
end

Instance Method Details

#load!Object



13
14
15
16
# File 'lib/lhs/proxy.rb', line 13

def load!
  return self if _loaded
  reload!
end

#reload!Object



18
19
20
21
22
23
24
# File 'lib/lhs/proxy.rb', line 18

def reload!
  raise 'No href found' unless _data.href
  data = _data.class.request(url: _data.href, method: :get)
  _data.merge_raw!(data)
  self._loaded = true
  self
end