Sha256: 6fb2fb50562a32a67094780f2e0019c8af2a79007cc9f8c62469664940d97097

Contents?: true

Size: 1.28 KB

Versions: 12

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

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

  autoload :Destroy,
    'dhs/concerns/item/destroy'
  autoload :Save,
    'dhs/concerns/item/save'
  autoload :Update,
    'dhs/concerns/item/update'
  autoload :Validation,
    'dhs/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, **_keyword_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
    DHS::Data.new(nested_data, _data._parent, _record, _data._request, _data._endpoint)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dhs-1.6.0 lib/dhs/item.rb
dhs-1.5.0 lib/dhs/item.rb
dhs-1.4.2 lib/dhs/item.rb
dhs-1.4.1 lib/dhs/item.rb
dhs-1.4.0 lib/dhs/item.rb
dhs-1.3.0 lib/dhs/item.rb
dhs-1.2.0 lib/dhs/item.rb
dhs-1.1.0 lib/dhs/item.rb
dhs-1.0.3 lib/dhs/item.rb
dhs-1.0.2 lib/dhs/item.rb
dhs-1.0.1 lib/dhs/item.rb
dhs-1.0.0 lib/dhs/item.rb