Module: FixtureReplacement::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

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



7
8
9
10
# File 'lib/fixture_replacement/class_methods.rb', line 7

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



3
4
5
# File 'lib/fixture_replacement/class_methods.rb', line 3

def included(_other_mod)
  FixtureReplacement.load_example_data
end

#load_example_dataObject



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

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

#rails_rootObject



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

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

#random_string(length = 10) ⇒ Object



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

def random_string(length=10)
  chars = ("a".."z").to_a
  string = ""
  1.upto(length) { |i| string << chars[rand(chars.size-1)]}
  string
end

#reload!Object



37
38
39
40
# File 'lib/fixture_replacement/class_methods.rb', line 37

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

#validate!Object



12
13
14
# File 'lib/fixture_replacement/class_methods.rb', line 12

def validate!
  AttributeBuilder.validate_instances!
end