Module: CustomFields::Types::Integer::Target::ClassMethods
- Defined in:
- lib/custom_fields/types/integer.rb
Instance Method Summary collapse
-
#apply_integer_custom_field(klass, rule) ⇒ Object
Add a integer field.
-
#integer_attribute_get(instance, name) ⇒ Hash
Build a hash storing the raw value for a string custom field of an instance.
-
#integer_attribute_set(instance, name, attributes) ⇒ Object
Set the value for the instance and the string field specified by the 2 params.
Instance Method Details
#apply_integer_custom_field(klass, rule) ⇒ Object
Add a integer field
17 18 19 20 21 22 23 |
# File 'lib/custom_fields/types/integer.rb', line 17 def apply_integer_custom_field(klass, rule) name = rule['name'] klass.field name, type: ::Integer, localize: rule['localized'] || false, default: rule['default'] klass.validates_presence_of name if rule['required'] klass.validates name, numericality: { only_integer: true }, if: ->(_x) { rule['required'] } end |
#integer_attribute_get(instance, name) ⇒ Hash
Build a hash storing the raw value for a string custom field of an instance.
33 34 35 |
# File 'lib/custom_fields/types/integer.rb', line 33 def integer_attribute_get(instance, name) default_attribute_get(instance, name) end |
#integer_attribute_set(instance, name, attributes) ⇒ Object
Set the value for the instance and the string field specified by the 2 params.
44 45 46 |
# File 'lib/custom_fields/types/integer.rb', line 44 def integer_attribute_set(instance, name, attributes) default_attribute_set(instance, name, attributes) end |