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



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

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

#load_example_dataObject



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

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

#rails_rootObject



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

def rails_root
  defined?(RAILS_ROOT) ? RAILS_ROOT : "."
end

#random_string(length = 10) ⇒ Object



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

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



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

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

#validate!Object



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

def validate!
  AttributeBuilder.validate_instances!
end