Class: LHS::Proxy

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

Overview

require File.dirname(__FILE__) + ‘/../../proxy’

Direct Known Subclasses

Collection, Item

Defined Under Namespace

Modules: Accessors, Create, Errors, Link

Constant Summary

Constants included from Accessors

Accessors::BLACKLISTED_KEYWORDS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Errors

#errors

Methods included from Create

#create, #create!

Constructor Details

#initialize(data) ⇒ Proxy

Returns a new instance of Proxy.



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

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

Instance Attribute Details

#_dataObject

prevent clashing with attributes of underlying data



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

def _data
  @_data
end

#_loadedObject

prevent clashing with attributes of underlying data



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

def _loaded
  @_loaded
end

Instance Method Details

#load!(options = nil) ⇒ Object



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

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

#recordObject



19
20
21
# File 'lib/lhs/proxy.rb', line 19

def record
  _data.class
end

#reload!(options = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/lhs/proxy.rb', line 28

def reload!(options = nil)
  raise 'No href found' unless _data.href
  options = {} if options.blank?

  data = _data.class.request(options.merge(url: _data.href, method: :get))
  _data.merge_raw!(data)
  self._loaded = true
  self
end