Class: MigrationValidators::Spec::Support::TestAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/migration_validators/spec/support/test_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(method_name, validators) ⇒ Object



40
41
42
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 40

def call method_name, validators
  (log[method_name] ||= []) << validators
end

.clearObject



33
34
35
36
37
38
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 33

def clear 
  @log = nil

  public_instance_methods.grep(/^validate_/) { |method_name| undef_method method_name }
  public_instance_methods.grep(/^remove_validate_/) { |method_name| undef_method method_name }
end

.logObject



29
30
31
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 29

def log
  @log ||= {}
end

.stub_method(method_name_prefix, validator_name, db_form) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 10

def stub_method method_name_prefix, validator_name, db_form
  method_name_suffix = db_form ? "_#{db_form}" : ""
  method_name = :"#{method_name_prefix}_#{validator_name}#{method_name_suffix}"

  define_method method_name do |validators|
    TestAdapter.call(method_name, validators)
    yield(validators) if block_given?
  end
end

.stub_remove_validate_method(validator_name, db_form = nil, &block) ⇒ Object



25
26
27
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 25

def stub_remove_validate_method validator_name, db_form = nil, &block
  stub_method :remove_validate, validator_name, db_form, &block
end

.stub_validate_method(validator_name, db_form = nil, &block) ⇒ Object



21
22
23
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 21

def stub_validate_method validator_name, db_form = nil, &block
  stub_method :validate, validator_name, db_form, &block
end

Instance Method Details

#nameObject



5
6
7
# File 'lib/migration_validators/spec/support/test_adapter.rb', line 5

def name 
  "TestAdapter"
end