Class: ARMocker::Models

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/a_r_mocker/models.rb

Overview

Generates multiple Models. Attributes passed are applied to every model generated.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(count, attributes = {}) ⇒ Models

have persisted

Parameters:

  • count (Integer)

    the number of models to be generated

  • attributes (Hash) (defaults to: {})

    attributes to be applied to every model



10
11
12
# File 'lib/a_r_mocker/models.rb', line 10

def initialize(count, attributes = {})
  @members = Array.new(count, ARMocker::Model.new(attributes.merge(persisted: attributes.slice(:_persisted))))
end

Class Method Details

.create(count, attributes = {}) ⇒ Object



14
15
16
# File 'lib/a_r_mocker/models.rb', line 14

def self.create(count, attributes = {})
  new(count, attributes.merge(_persisted: true))
end

Instance Method Details

#to_aObject



18
19
20
# File 'lib/a_r_mocker/models.rb', line 18

def to_a
  @members
end