Module: FixtureReplacement::ClassMethods

Includes:
RandomDataGenerators
Included in:
FixtureReplacement
Defined in:
lib/fixture_replacement/class_methods.rb

Instance Method Summary collapse

Methods included from RandomDataGenerators

#random_email, #random_first_name, #random_incrementing_number, #random_last_name, #random_name, #random_string

Instance Method Details

#attributes_for(fixture_name, options = {}, &block) ⇒ Object



9
10
11
12
# File 'lib/fixture_replacement/class_methods.rb', line 9

def attributes_for(fixture_name, options={}, &block)
  builder = AttributeBuilder.new(fixture_name, options, &block)
  MethodGenerator.new(builder, self).generate_methods
end

#included(_other_mod) ⇒ Object



5
6
7
# File 'lib/fixture_replacement/class_methods.rb', line 5

def included(_other_mod)
  FixtureReplacement.load!
end

#load!Object



18
19
20
21
22
# File 'lib/fixture_replacement/class_methods.rb', line 18

def load!
  load "#{rails_root}/db/example_data.rb"
rescue LoadError, NameError
  # no-op.  If the file is not found, don't panic
end

#rails_rootObject



24
25
26
27
28
# File 'lib/fixture_replacement/class_methods.rb', line 24

def rails_root
  ::Rails.root
rescue NameError
  "."
end

#reload!Object



30
31
32
33
# File 'lib/fixture_replacement/class_methods.rb', line 30

def reload!
  AttributeBuilder.clear_out_instances!
  load File.expand_path(File.dirname(__FILE__) + "/../fixture_replacement.rb")
end

#validate!Object



14
15
16
# File 'lib/fixture_replacement/class_methods.rb', line 14

def validate!
  AttributeBuilder.validate_instances!
end