Module: Aequitas::Rule::Format
- Defined in:
- lib/aequitas/rule/format.rb,
lib/aequitas/rule/format/proc.rb,
lib/aequitas/rule/format/regexp.rb
Defined Under Namespace
Constant Summary collapse
- FORMATS =
{ :email_address => Formats::EmailAddress, :url => Formats::Url }
- FORMAT_MESSAGES =
TODO: evaluate re-implementing custom error messages per format type previously these strings were wrapped in lambdas, which were, at one point, invoked with #try_call with the humanized attribute name and value
{ :email_address => '%s is not a valid email address', :url => '%s is not a valid URL', }
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
52 53 54 |
# File 'lib/aequitas/rule/format.rb', line 52 def format @format end |
Class Method Details
.new(attribute_name, options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aequitas/rule/format.rb', line 33 def self.new(attribute_name, ) format = .delete(:as) || .delete(:with) case format when Symbol regexp = FORMATS.fetch(format) do raise UnknownValidationFormat, "No such predefined format '#{format}'" end self::Regexp.new(attribute_name, .merge(:format => regexp, :format_name => format)) when ::Regexp self::Regexp.new(attribute_name, .merge(:format => format)) when ::Proc self::Proc.new(attribute_name, .merge(:format => format)) else raise UnknownValidationFormat, "Expected a Regexp, Symbol, or Proc format. Got: #{format.inspect}" end end |
.rules_for(attribute_name, options) ⇒ Object
26 27 28 |
# File 'lib/aequitas/rule/format.rb', line 26 def self.rules_for(attribute_name, ) Array(new(attribute_name, )) end |
Instance Method Details
#initialize(attribute_name, options) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/aequitas/rule/format.rb', line 54 def initialize(attribute_name, ) super @format = .fetch(:format) skip_condition.default_to_allowing_nil! skip_condition.default_to_allowing_blank! end |
#violation_type(resource) ⇒ Object
63 64 65 |
# File 'lib/aequitas/rule/format.rb', line 63 def violation_type(resource) :invalid end |