Sha256: c2f3d4d2b21d5b8a43cd864453e5b9b280f18c0a63165396b2a1ef6a288f4dc8

Contents?: true

Size: 1.42 KB

Versions: 16

Compression:

Stored size: 1.42 KB

Contents

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

class LHS::Record
  include All
  include Batch
  include Chainable
  include Configuration
  include Create
  include Equality
  include Endpoints
  include Find
  include FindBy
  include First
  include Includes
  include Mapping
  include Model
  include Pagination
  include Request
  include Scope

  delegate :_proxy, :_endpoint, :merge_raw!, :select, 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 }
    consider_custom_setters
  end

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

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

  def inspect
    "<#{self.class}#{_data._raw}>"
  end

  protected

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

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

  private

  def consider_custom_setters
    return if !instance_data.is_a?(Hash)
    instance_data.each do |k, v|
      if public_methods.include?("#{k}=".to_sym)
        send("#{k}=", v)
      end
    end
  end

  def instance_data
    if _data._proxy.is_a?(LHS::Collection) && _data._raw.is_a?(Hash)
      _data._raw.fetch(:items, [])
    else
      _data._raw
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
lhs-6.1.0 lib/lhs/record.rb
lhs-6.0.0 lib/lhs/record.rb
lhs-5.7.1 lib/lhs/record.rb
lhs-5.7.0 lib/lhs/record.rb
lhs-5.6.6 lib/lhs/record.rb
lhs-5.6.5 lib/lhs/record.rb
lhs-5.6.4 lib/lhs/record.rb
lhs-5.6.3 lib/lhs/record.rb
lhs-5.6.2 lib/lhs/record.rb
lhs-5.6.1 lib/lhs/record.rb
lhs-5.6.0 lib/lhs/record.rb
lhs-5.5.0 lib/lhs/record.rb
lhs-5.4.2 lib/lhs/record.rb
lhs-5.4.1 lib/lhs/record.rb
lhs-5.4.0 lib/lhs/record.rb
lhs-5.3.0 lib/lhs/record.rb