Sha256: b851e75d38bb023caf5015abaccfee685db2ee8ad63f7f6191bdb94d3fec09f2

Contents?: true

Size: 840 Bytes

Versions: 13

Compression:

Stored size: 840 Bytes

Contents

module Acfs::Model
  module Attributes

    # @api public
    #
    # Boolean attribute type. Use it in your model as an attribute type:
    #
    # @example
    #   class User
    #     include Acfs::Model
    #     attribute :name, :boolean
    #   end
    #
    # Given objects will be converted to string. The following strings
    # are considered true, everything else false:
    #
    #  true, on, yes
    #
    class Boolean < Base

      TRUE_VALUES = %w(true on yes)

      # @api public
      #
      # Cast given object to boolean.
      #
      # @param [Object] obj Object to cast.
      # @return [TrueClass, FalseClass] Casted boolean.
      #
      def cast_type(obj)
        return true if obj.is_a? TrueClass
        return false if obj.is_a? FalseClass

        TRUE_VALUES.include? obj.to_s
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
acfs-0.23.2.b206 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2.b205 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2.b204 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2.b203 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2.b200 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2.b199 lib/acfs/model/attributes/boolean.rb
acfs-0.23.2 lib/acfs/model/attributes/boolean.rb
acfs-0.23.1.b198 lib/acfs/model/attributes/boolean.rb
acfs-0.23.1 lib/acfs/model/attributes/boolean.rb
acfs-0.23.0.b197 lib/acfs/model/attributes/boolean.rb
acfs-0.22.2.b196 lib/acfs/model/attributes/boolean.rb
acfs-0.23.0 lib/acfs/model/attributes/boolean.rb
acfs-0.22.2.b194 lib/acfs/model/attributes/boolean.rb