Class: LHS::Collection
Overview
A collection is a special type of data that contains multiple items
Defined Under Namespace
Modules: InternalCollection
Constant Summary
Proxy::Accessors::BLACKLISTED_KEYWORDS
Instance Attribute Summary
Attributes inherited from Proxy
#_data, #_loaded
Instance Method Summary
collapse
Methods inherited from Proxy
#initialize, #load!, #reload!
#create, #create!
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
48
49
50
51
52
53
54
55
56
|
# File 'lib/lhs/collection.rb', line 48
def method_missing(name, *args, &block)
if _collection.respond_to?(name)
value = _collection.send(name, *args, &block)
return enclose_in_data(value) if value.is_a? Hash
value
elsif _data._raw.is_a?(Hash)
get(name, *args)
end
end
|
Instance Method Details
#_collection ⇒ Object
24
25
26
27
28
|
# File 'lib/lhs/collection.rb', line 24
def _collection
raw = _data._raw if _data._raw.is_a?(Array)
raw ||= _data._raw[items_key]
Collection.new(raw, _data, _record)
end
|
15
16
17
|
# File 'lib/lhs/collection.rb', line 15
def
_record.(_data)
end
|
#collection? ⇒ Boolean
30
31
32
|
# File 'lib/lhs/collection.rb', line 30
def collection?
true
end
|
#href ⇒ Object
19
20
21
22
|
# File 'lib/lhs/collection.rb', line 19
def href
return _data._raw[:href] if _data._raw.is_a? Hash
nil
end
|
#item? ⇒ Boolean
34
35
36
|
# File 'lib/lhs/collection.rb', line 34
def item?
false
end
|
#raw_items ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/lhs/collection.rb', line 38
def raw_items
if _raw.is_a?(Array)
_raw
else
_raw[items_key]
end
end
|