class LHS::Proxy
Proxy
makes different kind of data accessible If href is present it also alows loading/reloading
Attributes
_data[RW]
prevent clashing with attributes of underlying data
_loaded[RW]
prevent clashing with attributes of underlying data
Public Class Methods
new(data)
click to toggle source
# File lib/lhs/proxy.rb, line 24 def initialize(data) self._data = data self._loaded = false end
Public Instance Methods
load!(options = nil)
click to toggle source
# File lib/lhs/proxy.rb, line 33 def load!(options = nil) return self if _loaded reload!(options) end
record()
click to toggle source
# File lib/lhs/proxy.rb, line 29 def record _data.class end
reload!(options = nil)
click to toggle source
# 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
Private Instance Methods
as_record()
click to toggle source
# File lib/lhs/proxy.rb, line 51 def as_record @as_record ||= becomes(_record) end
merge_data_with_options(data, options)
click to toggle source
# File lib/lhs/proxy.rb, line 61 def merge_data_with_options(data, options) if options && options[:params] data.merge(options[:params]) else data end end
reload_options()
click to toggle source
# File lib/lhs/proxy.rb, line 55 def reload_options return { url: _data.href } if _data.href return { params: { id: as_record.id } } if as_record.id {} end