Class: NamedValidations
- Inherits:
-
Hash
- Object
- Hash
- NamedValidations
- Defined in:
- lib/named_validations.rb,
lib/named_validations/version.rb
Overview
Naming to ActiveModel/ActiveRecord validations
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.aliases ⇒ Array<Symbol>
Returns list of defined alias names.
- .define(name, *spec, &block) ⇒ Object
Instance Method Summary collapse
-
#absence(arg, *opts) ⇒ NamedValidations
Apply ‘absence` to `self` and return a new object.
-
#acceptance(arg, *opts) ⇒ NamedValidations
Apply ‘acceptance` to `self` and return a new object.
-
#associated(arg, *opts) ⇒ NamedValidations
Apply ‘associated` to `self` and return a new object.
-
#confirmation(arg, *opts) ⇒ NamedValidations
Apply ‘confirmation` to `self` and return a new object.
-
#exclusion(arg, *opts) ⇒ NamedValidations
Apply ‘exclusion` to `self` and return a new object.
-
#extractable_options? ⇒ Boolean
Returns true.
-
#format(arg, *opts) ⇒ NamedValidations
Apply ‘format` to `self` and return a new object.
-
#inclusion(arg, *opts) ⇒ NamedValidations
Apply ‘inclusion` to `self` and return a new object.
-
#inspect ⇒ Object
Inspects self.
-
#length(arg, *opts) ⇒ NamedValidations
Apply ‘length` to `self` and return a new object.
-
#numericality(arg, *opts) ⇒ NamedValidations
Apply ‘numericality` to `self` and return a new object.
-
#presence(arg, *opts) ⇒ NamedValidations
Apply ‘presence` to `self` and return a new object.
-
#size(arg, *opts) ⇒ NamedValidations
Apply ‘size` to `self` and return a new object.
-
#uniqueness(arg, *opts) ⇒ NamedValidations
Apply ‘uniqueness` to `self` and return a new object.
Class Method Details
.aliases ⇒ Array<Symbol>
Returns list of defined alias names
35 36 37 |
# File 'lib/named_validations.rb', line 35 def aliases @aliases ||= [] end |
.define(name, validation, params) ⇒ Object .define(name, block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/named_validations.rb', line 25 def define(name, *spec, &block) raise ArgumentError, "reserved name #{name}" if RESERVED.include?(name) return define_by_block(name, block) if spec.empty? validation, params, = spec define_by_value(name, validation, params) end |
Instance Method Details
#absence(arg, *opts) ⇒ NamedValidations
Apply ‘absence` to `self` and return a new object
70 |
# File 'lib/named_validations.rb', line 70 define_for :absence |
#acceptance(arg, *opts) ⇒ NamedValidations
Apply ‘acceptance` to `self` and return a new object
75 |
# File 'lib/named_validations.rb', line 75 define_for :acceptance |
#associated(arg, *opts) ⇒ NamedValidations
Apply ‘associated` to `self` and return a new object
80 |
# File 'lib/named_validations.rb', line 80 define_for :associated |
#confirmation(arg, *opts) ⇒ NamedValidations
Apply ‘confirmation` to `self` and return a new object
71 |
# File 'lib/named_validations.rb', line 71 define_for :confirmation |
#exclusion(arg, *opts) ⇒ NamedValidations
Apply ‘exclusion` to `self` and return a new object
76 |
# File 'lib/named_validations.rb', line 76 define_for :exclusion |
#extractable_options? ⇒ Boolean
This method is needed for ActiveSupport ‘Hash#extract_options!`.
Returns true
89 90 91 |
# File 'lib/named_validations.rb', line 89 def true end |
#format(arg, *opts) ⇒ NamedValidations
Apply ‘format` to `self` and return a new object
72 |
# File 'lib/named_validations.rb', line 72 define_for :format |
#inclusion(arg, *opts) ⇒ NamedValidations
Apply ‘inclusion` to `self` and return a new object
73 |
# File 'lib/named_validations.rb', line 73 define_for :inclusion |
#inspect ⇒ Object
Inspects self
94 95 96 97 98 99 |
# File 'lib/named_validations.rb', line 94 def inspect klass = self.class class_name = klass.name || Kernel.format('(Anonymous:0x%x)', klass.object_id) Kernel.format('#<%s:0x%x>', class_name, object_id) end |
#length(arg, *opts) ⇒ NamedValidations
Apply ‘length` to `self` and return a new object
77 |
# File 'lib/named_validations.rb', line 77 define_for :length |
#numericality(arg, *opts) ⇒ NamedValidations
Apply ‘numericality` to `self` and return a new object
74 |
# File 'lib/named_validations.rb', line 74 define_for :numericality |
#presence(arg, *opts) ⇒ NamedValidations
Apply ‘presence` to `self` and return a new object
78 |
# File 'lib/named_validations.rb', line 78 define_for :presence |
#size(arg, *opts) ⇒ NamedValidations
Apply ‘size` to `self` and return a new object
81 |
# File 'lib/named_validations.rb', line 81 define_for :size |
#uniqueness(arg, *opts) ⇒ NamedValidations
Apply ‘uniqueness` to `self` and return a new object
79 |
# File 'lib/named_validations.rb', line 79 define_for :uniqueness |