Sha256: a0e95d4ce1f22562db6ec26b54ec167e86f34c680e86ae92e078575a9223ee2d

Contents?: true

Size: 1.27 KB

Versions: 33

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

# An item is a concrete record.
# It can be part of another proxy like collection.
class LHS::Item < LHS::Proxy

  autoload :Destroy,
    'lhs/concerns/item/destroy'
  autoload :Save,
    'lhs/concerns/item/save'
  autoload :Update,
    'lhs/concerns/item/update'
  autoload :Validation,
    'lhs/concerns/item/validation'

  include Create
  include Destroy
  include Save
  include Update
  include Validation

  delegate :map, :present?, :blank?, :empty?, to: :_raw, allow_nil: true
  delegate :_raw, to: :_data

  def collection?
    false
  end

  def item?
    true
  end

  def respond_to?(sym, include_all = false)
    if sym == :to_ary
      false
    else
      super(sym, include_all)
    end
  end

  protected

  def method_missing(name, *args, &_block)
    return set(name, args) if name.to_s[/=$/]
    get(name, *args)
  end

  def respond_to_missing?(name, _include_all = false)
    # We accept every message that does not belong to set of keywords
    !BLACKLISTED_KEYWORDS.include?(name.to_s)
  end

  def unwrap_nested_item
    return _data unless _record.item_key
    nested_data = _data.dig(*_record.item_key)
    return _data unless nested_data
    LHS::Data.new(nested_data, _data._parent, _record, _data._request, _data._endpoint)
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
lhs-26.2.0 lib/lhs/item.rb
lhs-26.1.0 lib/lhs/item.rb
lhs-26.0.1 lib/lhs/item.rb
lhs-26.0.0 lib/lhs/item.rb
lhs-25.2.0 lib/lhs/item.rb
lhs-25.1.0 lib/lhs/item.rb
lhs-25.0.4 lib/lhs/item.rb
lhs-25.0.3 lib/lhs/item.rb
lhs-25.0.2 lib/lhs/item.rb
lhs-25.0.1 lib/lhs/item.rb
lhs-25.0.0 lib/lhs/item.rb
lhs-24.1.2 lib/lhs/item.rb
lhs-24.1.1 lib/lhs/item.rb
lhs-24.1.0 lib/lhs/item.rb
lhs-24.1.0.pre.2 lib/lhs/item.rb
lhs-24.1.0.pre.1 lib/lhs/item.rb
lhs-24.0.0 lib/lhs/item.rb
lhs-23.0.2 lib/lhs/item.rb
lhs-23.0.1 lib/lhs/item.rb
lhs-23.0.0 lib/lhs/item.rb