Class: LHS::Collection

Inherits:
Proxy
  • Object
show all
Includes:
InternalCollection
Defined in:
lib/lhs/collection.rb,
lib/lhs/concerns/collection/internal_collection.rb

Overview

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

Defined Under Namespace

Modules: InternalCollection

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)



33
34
35
36
37
# File 'lib/lhs/collection.rb', line 33

def method_missing(name, *args, &block)
  value = _collection.send(name, *args, &block)
  return enclose_in_data(value) if value.is_a? Hash
  value
end

Instance Method Details

#_collectionObject



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

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

#_paginationObject



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

def _pagination
  _record.pagination(_data)
end

#collection?Boolean

Returns:

  • (Boolean)


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

def collection?
  true
end

#hrefObject



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

def href
  _data._raw[:href]
end