Class: StrapiModel::Relation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/strapi_model/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, entries = []) ⇒ Relation

Returns a new instance of Relation.



7
8
9
10
# File 'lib/strapi_model/relation.rb', line 7

def initialize(klass, entries = [])
  @klass = klass
  @entries = entries
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/strapi_model/relation.rb', line 18

def method_missing(method, *args)
  if entries.respond_to?(method)
    entries.send(method, *args)
  else
    super
  end
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



5
6
7
# File 'lib/strapi_model/relation.rb', line 5

def entries
  @entries
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/strapi_model/relation.rb', line 5

def klass
  @klass
end

Instance Method Details

#eachObject



12
13
14
15
16
# File 'lib/strapi_model/relation.rb', line 12

def each
  entries.each do |item|
    yield item
  end
end