Sha256: e5dad757df4cd9f5cb54e316a3bae44cbf337e5dc2cb3d38227cdb8463049023

Contents?: true

Size: 838 Bytes

Versions: 6

Compression:

Stored size: 838 Bytes

Contents

module DataMapper
  class Property
    class Boolean < Object
      include PassThroughLoadDump

      primitive ::TrueClass

      TRUE_VALUES  = [ 1, '1', 't', 'T', 'true',  'TRUE'  ].freeze
      FALSE_VALUES = [ 0, '0', 'f', 'F', 'false', 'FALSE' ].freeze
      BOOLEAN_MAP  = Hash[
        TRUE_VALUES.product([ true ]) + FALSE_VALUES.product([ false ]) ].freeze

      def primitive?(value)
        value == true || value == false
      end

      # Typecast a value to a true or false
      #
      # @param [Integer, #to_str] value
      #   value to typecast
      #
      # @return [Boolean]
      #   true or false constructed from value
      #
      # @api private
      def typecast_to_primitive(value)
        BOOLEAN_MAP.fetch(value, value)
      end
    end # class Boolean
  end # class Property
end # module DataMapper

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ardm-core-1.3.0 lib/dm-core/property/boolean.rb
ardm-core-1.2.1 lib/dm-core/property/boolean.rb
dm-core-1.2.1 lib/dm-core/property/boolean.rb
dm-core-1.2.0 lib/dm-core/property/boolean.rb
dm-core-1.2.0.rc2 lib/dm-core/property/boolean.rb
dm-core-1.2.0.rc1 lib/dm-core/property/boolean.rb