class DHS::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/dhs/proxy.rb, line 25 def initialize(data) self._data = data self._loaded = false end
Public Instance Methods
load!(options = nil)
click to toggle source
# File lib/dhs/proxy.rb, line 34 def load!(options = nil) return self if _loaded reload!(options) end
record()
click to toggle source
# File lib/dhs/proxy.rb, line 30 def record _data.class end
reload!(options = nil)
click to toggle source
# File lib/dhs/proxy.rb, line 39 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/dhs/proxy.rb, line 52 def as_record @as_record ||= becomes(_record) end
merge_data_with_options(data, options)
click to toggle source
# File lib/dhs/proxy.rb, line 62 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/dhs/proxy.rb, line 56 def reload_options return { url: _data.href } if _data.href return { params: { id: as_record.id } } if as_record.id {} end