Sha256: 8842b9b8f5f5ec0a673b72c19fbb8e6ced960eba4920088451f6110aff917c6a

Contents?: true

Size: 740 Bytes

Versions: 7

Compression:

Stored size: 740 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 Create
  include Link

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

  def initialize(data)
    self._data = data
    self._loaded = false
  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-7.3.0 lib/lhs/proxy.rb
lhs-7.2.5 lib/lhs/proxy.rb
lhs-7.2.4 lib/lhs/proxy.rb
lhs-7.2.3 lib/lhs/proxy.rb
lhs-7.2.2 lib/lhs/proxy.rb
lhs-7.2.1 lib/lhs/proxy.rb
lhs-7.2.0 lib/lhs/proxy.rb