Class: LHS::Item

Inherits:
Proxy show all
Includes:
Destroy, Save, Update
Defined in:
lib/lhs/item.rb,
lib/lhs/concerns/item/save.rb,
lib/lhs/concerns/item/update.rb,
lib/lhs/concerns/item/destroy.rb

Overview

An item is a concrete record. It can be part of another proxy like collection.

Defined Under Namespace

Modules: Destroy, Save, Update

Instance Attribute Summary collapse

Attributes inherited from Proxy

#_data, #_loaded

Instance Method Summary collapse

Methods included from Update

#update, #update!

Methods included from Save

#save, #save!

Methods included from Destroy

#destroy

Methods inherited from Proxy

#initialize, #load!, #reload!

Constructor Details

This class inherits a constructor from LHS::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lhs/item.rb', line 20

def method_missing(name, *args, &block)
  return set(name, args.try(&:first)) if name.to_s[/=$/]
  name = args.first if name == :[]
  value = _data._raw[name.to_s]
  value = _data._raw[name.to_sym] if value.nil?
  if value.is_a?(Hash)
    handle_hash(value)
  elsif value.is_a?(Array)
    data = LHS::Data.new(value, _data)
    collection = LHS::Collection.new(data)
    LHS::Data.new(collection, _data)
  else
    convert(value)
  end
end

Instance Attribute Details

#errorsObject

prevent clashing with attributes of underlying data



12
13
14
# File 'lib/lhs/item.rb', line 12

def errors
  @errors
end

Instance Method Details

#_rawObject



14
15
16
# File 'lib/lhs/item.rb', line 14

def _raw
  _data._raw
end