Class: ActiveMocker::ModelSchemaCollection
- Inherits:
-
Object
- Object
- ActiveMocker::ModelSchemaCollection
- Includes:
- Enumerable
- Defined in:
- lib/active_mocker/model_schema.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Instance Method Summary collapse
- #[](val) ⇒ Object
- #each(&block) ⇒ Object
- #find_by(options = {}) ⇒ Object
- #find_by_in_relationships(options = {}) ⇒ Object
-
#initialize(collection) ⇒ ModelSchemaCollection
constructor
A new instance of ModelSchemaCollection.
Constructor Details
#initialize(collection) ⇒ ModelSchemaCollection
Returns a new instance of ModelSchemaCollection.
21 22 23 |
# File 'lib/active_mocker/model_schema.rb', line 21 def initialize(collection) @collection = collection end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
19 20 21 |
# File 'lib/active_mocker/model_schema.rb', line 19 def collection @collection end |
Instance Method Details
#[](val) ⇒ Object
46 47 48 |
# File 'lib/active_mocker/model_schema.rb', line 46 def [](val) collection[val] end |
#each(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/active_mocker/model_schema.rb', line 25 def each(&block) collection.each do |item| block.call(item) end end |
#find_by(options = {}) ⇒ Object
31 32 33 |
# File 'lib/active_mocker/model_schema.rb', line 31 def find_by(={}) collection.select{|c| c.send(.keys.first) == .values.first}.first end |
#find_by_in_relationships(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/active_mocker/model_schema.rb', line 35 def find_by_in_relationships(={}) result = nil collection.each do |item| result = item.relationships.select do |attr| attr.send(.keys.first) == .values.first end end result end |