Sha256: d365921108f38a825f1a977c58f199c1df68c370db5c5c83b5cdd64ea8e9b09c

Contents?: true

Size: 1.78 KB

Versions: 23

Compression:

Stored size: 1.78 KB

Contents

module CustomFields
  module Types
    module Integer

      module Field; end

      module Target
        extend ActiveSupport::Concern

        module ClassMethods

          # Add a integer field
          #
          # @param [ Class ] klass The class to modify
          # @param [ Hash ] rule It contains the name of the field and if it is required or not
          #
          def apply_integer_custom_field(klass, rule)
            name = rule['name']

            klass.field name, type: ::Integer, localize: rule['localized'] || false
            klass.validates_presence_of name if rule['required']
            klass.validates name, numericality: { only_integer: true }, if: ->(x){ rule['required'] }
          end

          # Build a hash storing the raw value for
          # a string custom field of an instance.
          #
          # @param [ Object ] instance An instance of the class enhanced by the custom_fields
          # @param [ String ] name The name of the string custom field
          #
          # @return [ Hash ] field name => raw value
          #
          def integer_attribute_get(instance, name)
            self.default_attribute_get(instance, name)
          end

          # Set the value for the instance and the string field specified by
          # the 2 params.
          #
          # @param [ Object ] instance An instance of the class enhanced by the custom_fields
          # @param [ String ] name The name of the string custom field
          # @param [ Hash ] attributes The attributes used to fetch the values
          #
          def integer_attribute_set(instance, name, attributes)
            self.default_attribute_set(instance, name, attributes)
          end

        end # ClassMethods

      end # Target

    end # Integer
  end # Types
end # CustomFields

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
custom_fields-2.5.0 lib/custom_fields/types/integer.rb
custom_fields-2.5.0.rc1 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc8 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc7 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc6 lib/custom_fields/types/integer.rb
custom_fields-2.3.4 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc5 lib/custom_fields/types/integer.rb
custom_fields-2.3.3 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc4 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc3 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc2 lib/custom_fields/types/integer.rb
custom_fields-2.3.2 lib/custom_fields/types/integer.rb
custom_fields-2.4.0.rc1 lib/custom_fields/types/integer.rb
gnuside-custom_fields-2.3.2.2 lib/custom_fields/types/integer.rb
gnuside-custom_fields-2.3.2 lib/custom_fields/types/integer.rb
gnuside-custom_fields-2.3.1.1 lib/custom_fields/types/integer.rb
gnuside-custom_fields-2.3.1 lib/custom_fields/types/integer.rb
custom_fields-2.3.1 lib/custom_fields/types/integer.rb
custom_fields-2.3.0 lib/custom_fields/types/integer.rb
custom_fields-2.2.3 lib/custom_fields/types/integer.rb