Class: LHS::Proxy

Inherits:
Object
  • Object
show all
Includes:
Problems, Accessors, Create, Link
Defined in:
lib/lhs/proxy.rb,
lib/lhs/concerns/proxy/link.rb,
lib/lhs/concerns/proxy/create.rb,
lib/lhs/concerns/proxy/problems.rb,
lib/lhs/concerns/proxy/accessors.rb

Overview

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

Direct Known Subclasses

Collection, Item

Defined Under Namespace

Modules: Accessors, Create, Link, Problems

Constant Summary

Constants included from Accessors

Accessors::BLACKLISTED_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Create

#create, #create!

Methods included from Accessors

#clear_cache!

Constructor Details

#initialize(data) ⇒ Proxy

Returns a new instance of Proxy.


24
25
26
27
# File 'lib/lhs/proxy.rb', line 24

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

Instance Attribute Details

#_dataObject

prevent clashing with attributes of underlying data


21
22
23
# File 'lib/lhs/proxy.rb', line 21

def _data
  @_data
end

#_loadedObject

prevent clashing with attributes of underlying data


21
22
23
# File 'lib/lhs/proxy.rb', line 21

def _loaded
  @_loaded
end

Instance Method Details

#load!(options = nil) ⇒ Object


33
34
35
36
# File 'lib/lhs/proxy.rb', line 33

def load!(options = nil)
  return self if _loaded
  reload!(options)
end

#recordObject


29
30
31
# File 'lib/lhs/proxy.rb', line 29

def record
  _data.class
end

#reload!(options = nil) ⇒ Object


38
39
40
41
42
43
44
45
46
47
# File 'lib/lhs/proxy.rb', line 38

def reload!(options = nil)
  options = {} if options.blank?
  data = _data.class.request(
    options.merge(method: :get).merge(reload_options)
  )
  _data.merge_raw!(data.unwrap(:item_key))
  self._loaded = true
  return becomes(_record) if _record
  self
end