Sha256: 637c1fc3196d670736f9817d9d7274c64621baeffdae37cc34eeaa42aa32a3a1

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

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

class LHS::Record
  include All
  include Batch
  include Create
  include Endpoints
  include Find
  include FindBy
  include First
  include Mapping
  include Model
  include Includes
  include Request
  include Where
  include Pagination

  delegate :_proxy, to: :_data

  def initialize(data = nil)
    data = LHS::Data.new({}, nil, self.class) unless data
    data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data)
    define_singleton_method(:_data) { data }
    instance_data =
      if data._proxy.is_a?(LHS::Item) && data._raw.is_a?(Hash)
        data._raw
      elsif data._proxy.is_a?(LHS::Collection) && data._raw.is_a?(Hash)
        data._raw.fetch(:items, [])
      else
        data._raw
      end
    instance_variable_set('@data', instance_data)
  end

  def as_json(options = nil)
    _data.as_json(options)
  end

  def self.build(data = nil)
    new(data)
  end

  protected

  def method_missing(name, *args, &block)
    _data._proxy.send(name, *args, &block)
  end

  def respond_to_missing?(name, include_all = false)
    _data.respond_to_missing?(name, include_all)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lhs-3.2.0 lib/lhs/record.rb
lhs-3.1.3 lib/lhs/record.rb
lhs-3.1.1 lib/lhs/record.rb
lhs-3.1.0 lib/lhs/record.rb