Class: RailsParam::Validator
- Inherits:
-
Object
- Object
- RailsParam::Validator
- Extended by:
- Forwardable
- Defined in:
- lib/rails_param/validator.rb,
lib/rails_param/validator/in.rb,
lib/rails_param/validator/is.rb,
lib/rails_param/validator/max.rb,
lib/rails_param/validator/min.rb,
lib/rails_param/validator/blank.rb,
lib/rails_param/validator/custom.rb,
lib/rails_param/validator/format.rb,
lib/rails_param/validator/required.rb,
lib/rails_param/validator/max_length.rb,
lib/rails_param/validator/min_length.rb
Defined Under Namespace
Classes: Blank, Custom, Format, In, Is, Max, MaxLength, Min, MinLength, Required
Constant Summary collapse
- VALIDATABLE_OPTIONS =
[ :blank, :custom, :format, :in, :is, :max_length, :max, :min_length, :min, :required ].freeze
Instance Attribute Summary collapse
-
#parameter ⇒ Object
readonly
Returns the value of attribute parameter.
Instance Method Summary collapse
-
#initialize(parameter) ⇒ Validator
constructor
A new instance of Validator.
- #valid! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(parameter) ⇒ Validator
Returns a new instance of Validator.
24 25 26 |
# File 'lib/rails_param/validator.rb', line 24 def initialize(parameter) @parameter = parameter end |
Instance Attribute Details
#parameter ⇒ Object (readonly)
Returns the value of attribute parameter.
7 8 9 |
# File 'lib/rails_param/validator.rb', line 7 def parameter @parameter end |
Instance Method Details
#valid! ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/rails_param/validator.rb', line 37 def valid! return if valid_value? raise InvalidParameterError.new( , param: name, options: ) end |
#validate! ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/rails_param/validator.rb', line 28 def validate! .each_key do |key| next unless VALIDATABLE_OPTIONS.include? key class_name = camelize(key) Validator.const_get(class_name).new(parameter).valid! end end |