Class FixtureReplacement::MethodGenerator

  1. lib/fixture_replacement/method_generator.rb (view online)
Parent: Object

Methods

public class

  1. new

public instance

  1. generate_methods

Public class methods

new (builder, evaluation_module)
[show source]
   # File lib/fixture_replacement/method_generator.rb, line 3
3:     def initialize(builder, evaluation_module)
4:       @builder           = builder
5:       @evaluation_module = evaluation_module
6:     end

Public instance methods

generate_methods ()
[show source]
    # File lib/fixture_replacement/method_generator.rb, line 8
 8:     def generate_methods
 9:       builder       = @builder
10:       builder_name  = builder.fixture_name
11: 
12:       @evaluation_module.module_eval do
13:         define_method("valid_#{builder_name}_attributes") do |*args|
14:           obj = __send__ "new_#{builder_name}"
15:           obj.attributes
16:         end
17: 
18:         define_method("create_#{builder_name}") do |*args|
19:           obj = __send__("new_#{builder_name}", *args)
20:           obj.save!
21:           obj
22:         end
23: 
24:         define_method("new_#{builder_name}") do |*args|
25:           new_object = builder.instantiate(*args)
26:         end
27: 
28:         define_method("default_#{builder_name}") do |*args|
29:           warning = "default_#{builder_name} has been deprecated. "
30:           warning << "Please replace instances of default_#{builder_name} with the new_#{builder_name} method"
31:           Kernel.warn(warning)
32: 
33:           __send__ "new_#{builder_name}"
34:         end
35:       end
36:     end