Sha256: d97aefc80613cb1fd96723130b17dbf52f7c1d8a070864c1c2ee913970df4fc5

Contents?: true

Size: 812 Bytes

Versions: 7

Compression:

Stored size: 812 Bytes

Contents

Dir[File.dirname(__FILE__) + '/concerns/proxy/*.rb'].each { |file| require file }

# Proxy makes different kind of data accessible
# If href is present it also alows loading/reloading
class LHS::Proxy
  include Accessors
  include Create
  include Errors
  include Link

  # prevent clashing with attributes of underlying data
  attr_accessor :_data, :_loaded

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

  def record
    _data.class
  end

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

  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lhs-11.3.3 lib/lhs/proxy.rb
lhs-11.3.2 lib/lhs/proxy.rb
lhs-11.3.1 lib/lhs/proxy.rb
lhs-11.3.0 lib/lhs/proxy.rb
lhs-11.2.2 lib/lhs/proxy.rb
lhs-11.2.1 lib/lhs/proxy.rb
lhs-11.2.0 lib/lhs/proxy.rb