Class: Mockumentary::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/mockumentary/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject

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

Returns:

  • (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