Class: Field::CNPJ
Instance Attribute Summary
Attributes inherited from Base
#fieldset, #form, #name, #value
Instance Method Summary collapse
Methods inherited from Base
#add_attributes, #form?, #initialize
Constructor Details
This class inherits a constructor from Field::Base
Instance Method Details
#add_validations(klass, options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/field/cnpj.rb', line 6 def add_validations(klass, ) klass.validates name, cnpj: true if [:uniqueness] unless [:uniqueness].is_a?(Hash) && [:uniqueness][:model] raise Field::Error, "Must specify a model to validate uniqueness" end required = { attribute: name, allow_nil: true, allow_blank: true } klass.validates name, uniqueness: [:uniqueness].merge(required) .reject! { |k| k == :uniqueness } end super end |
#attribute ⇒ Object
27 28 29 |
# File 'lib/field/cnpj.rb', line 27 def attribute ::Attribute::CNPJ end |
#output ⇒ Object
31 32 33 |
# File 'lib/field/cnpj.rb', line 31 def output ::CNPJ.new(value).formatted end |