Class: LHS::Collection

Inherits:
Proxy
  • Object
show all
Defined in:
lib/lhs/collection.rb

Overview

A collection is a special type of data that contains multiple items

Defined Under Namespace

Classes: Collection

Instance Attribute Summary

Attributes inherited from Proxy

#_data, #_loaded

Instance Method Summary collapse

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)



35
36
37
38
39
40
41
42
43
44
# File 'lib/lhs/collection.rb', line 35

def method_missing(name, *args, &block)
  value = _collection.send(name, *args, &block)
  if value.is_a? Hash
    data = LHS::Data.new(value, _data)
    item = LHS::Item.new(data)
    LHS::Data.new(item, _data)
  else
    value
  end
end

Instance Method Details

#_collectionObject



25
26
27
28
29
# File 'lib/lhs/collection.rb', line 25

def _collection
  raw = _data._raw if _data._raw.is_a?(Array)
  raw ||= _data._raw[:items]
  Collection.new(raw, _data, _data._record_class)
end

#hrefObject



21
22
23
# File 'lib/lhs/collection.rb', line 21

def href
  _data._raw[:href]
end

#limitObject



13
14
15
# File 'lib/lhs/collection.rb', line 13

def limit
  _data._raw[:limit]
end

#offsetObject



17
18
19
# File 'lib/lhs/collection.rb', line 17

def offset
  _data._raw[:offset]
end

#totalObject



9
10
11
# File 'lib/lhs/collection.rb', line 9

def total
  _data._raw[:total]
end