Class: ExtractedValidator::Base

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ActiveRecord::Validations
Defined in:
lib/extracted_validator/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



17
18
19
# File 'lib/extracted_validator/base.rb', line 17

def method_missing(name, *args, &block)
  model.send name, *args, &block
end

Class Method Details

.[](model) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/extracted_validator/base.rb', line 29

def self.[](model)
  Class.new(self) do
    define_singleton_method :model_class do
      model
    end

    define_singleton_method :model_name do
      ActiveModel::Name.new(model)
    end
  end
end

.method_missing(name, *args, &block) ⇒ Object



25
26
27
# File 'lib/extracted_validator/base.rb', line 25

def self.method_missing(name, *args, &block)
  model_class.send name, *args, &block
end

Instance Method Details

#add_error(message, scope: :base) ⇒ Object



21
22
23
# File 'lib/extracted_validator/base.rb', line 21

def add_error(message, scope: :base)
  errors[scope] << message
end