Class: CreateValid::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/create_valid.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_case) ⇒ Factory

Returns a new instance of Factory.



30
31
32
# File 'lib/create_valid.rb', line 30

def initialize(test_case)
  @test_case, @stack = test_case, []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/create_valid.rb', line 34

def method_missing(method, *args, &block)
  if method.to_s =~ ::CreateValid::MAGIC_METHOD
    auto_create_instance($3,                            # class name
                         $2 == 'valid_',                # valid?
                         $1 == 'create',                # save to DB?
                         ($5.split('_and_') rescue []), # features to append
                         args.shift || {})              # extra attributes to merge
  else
    super
  end
end

Instance Method Details

#instanceObject Also known as: i



46
47
48
# File 'lib/create_valid.rb', line 46

def instance
  @stack.last
end