Class: SampleModels::Model::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, config = {}) ⇒ Validation

Returns a new instance of Validation.



88
89
90
# File 'lib/sample_models/model.rb', line 88

def initialize(type, config = {})
  @type, @config = type, config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



92
93
94
95
96
97
98
99
100
101
# File 'lib/sample_models/model.rb', line 92

def method_missing(meth, *args, &block)
  type_predicates = %w(
    email_format? inclusion? length? presence? uniqueness?
  )
  if type_predicates.include?(meth.to_s)
    @type == "validates_#{meth.to_s.chop}_of".to_sym
  else
    super
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



86
87
88
# File 'lib/sample_models/model.rb', line 86

def config
  @config
end

#typeObject (readonly)

Returns the value of attribute type.



86
87
88
# File 'lib/sample_models/model.rb', line 86

def type
  @type
end