Class: ActiveMocker::ModelSchemaCollection Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_mocker/model_schema.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ ModelSchemaCollection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ModelSchemaCollection.



22
23
24
# File 'lib/active_mocker/model_schema.rb', line 22

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#collectionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/active_mocker/model_schema.rb', line 20

def collection
  @collection
end

Instance Method Details

#[](val) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
# File 'lib/active_mocker/model_schema.rb', line 47

def [](val)
  collection[val]
end

#each(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
# File 'lib/active_mocker/model_schema.rb', line 26

def each(&block)
  collection.each do |item|
    block.call(item)
  end
end

#find_by(options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/active_mocker/model_schema.rb', line 32

def find_by(options={})
  collection.select{|c| c.send(options.keys.first) == options.values.first}.first
end

#find_by_in_relationships(options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
43
44
# File 'lib/active_mocker/model_schema.rb', line 36

def find_by_in_relationships(options={})
  result = nil
  collection.each do |item|
    result = item.relationships.select do |attr|
      attr.send(options.keys.first) == options.values.first
    end
  end
  result
end