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.



96
97
98
# File 'lib/sample_models/model.rb', line 96

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



100
101
102
103
104
105
106
107
108
109
# File 'lib/sample_models/model.rb', line 100

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.



94
95
96
# File 'lib/sample_models/model.rb', line 94

def config
  @config
end

#typeObject (readonly)

Returns the value of attribute type.



94
95
96
# File 'lib/sample_models/model.rb', line 94

def type
  @type
end