Sha256: 0d5b7ef420fb84582ca6274c8f5b1e9b5c4f9aa67293542f421c98bb4f5fb723

Contents?: true

Size: 563 Bytes

Versions: 3

Compression:

Stored size: 563 Bytes

Contents

module Acfs::Resource::Attributes
  # @api public
  #
  # Integer attribute type. Use it in your model as an attribute type:
  #
  # @example
  #   class User < Acfs::Resource
  #     attribute :name, :integer
  #   end
  #
  class Integer < Base
    # @api public
    #
    # Cast given object to integer.
    #
    # @param [Object] obj Object to cast.
    # @return [Fixnum] Casted object as fixnum.
    #
    def cast_type(obj)
      return 0 if obj == ''

      Integer obj
    rescue ArgumentError => e
      raise TypeError.new e.message
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
acfs-0.45.0 lib/acfs/resource/attributes/integer.rb
acfs-0.44.0 lib/acfs/resource/attributes/integer.rb
acfs-0.43.2 lib/acfs/resource/attributes/integer.rb