Class: Mockumentary::Collection
- Inherits:
-
Array
- Object
- Array
- Mockumentary::Collection
- Defined in:
- lib/mockumentary/collection.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #build(opts = {}) ⇒ Object
- #create(opts = {}) ⇒ Object (also: #create!)
- #delete(*args) ⇒ Object
- #exist?(element) ⇒ Boolean
-
#initialize(klass) ⇒ Collection
constructor
A new instance of Collection.
- #mock(i = 1) ⇒ Object
- #mock!(i = 1) ⇒ Object
Constructor Details
#initialize(klass) ⇒ Collection
Returns a new instance of Collection.
5 6 7 |
# File 'lib/mockumentary/collection.rb', line 5 def initialize(klass) self.type = klass end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/mockumentary/collection.rb', line 3 def type @type end |
Instance Method Details
#build(opts = {}) ⇒ Object
19 20 21 22 |
# File 'lib/mockumentary/collection.rb', line 19 def build(opts={}) self << type.new(opts) self end |
#create(opts = {}) ⇒ Object Also known as: create!
24 25 26 27 |
# File 'lib/mockumentary/collection.rb', line 24 def create(opts={}) self << type.new(opts).save self end |
#delete(*args) ⇒ Object
31 32 33 34 |
# File 'lib/mockumentary/collection.rb', line 31 def delete(*args) args.each {|e| super(e)} self end |
#exist?(element) ⇒ Boolean
40 41 42 |
# File 'lib/mockumentary/collection.rb', line 40 def exist?(element) map(&:id).include?(element.id) end |
#mock(i = 1) ⇒ Object
9 10 11 12 |
# File 'lib/mockumentary/collection.rb', line 9 def mock(i=1) (1..i).each { self << type.mock } self end |
#mock!(i = 1) ⇒ Object
14 15 16 17 |
# File 'lib/mockumentary/collection.rb', line 14 def mock!(i=1) (1..i).each { self << type.mock! } self end |