Sha256: 8f576b4222feda3de87a1c21fbca21d70c9c06331b2baed113ddd75f75d995ad

Contents?: true

Size: 842 Bytes

Versions: 74

Compression:

Stored size: 842 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 1)

      # @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

74 entries across 74 versions & 1 rubygems

Version Path
acfs-0.42.0 lib/acfs/model/attributes/boolean.rb
acfs-0.41.1 lib/acfs/model/attributes/boolean.rb
acfs-0.41.1.beta1 lib/acfs/model/attributes/boolean.rb
acfs-0.41.0 lib/acfs/model/attributes/boolean.rb
acfs-0.40.1.rc1 lib/acfs/model/attributes/boolean.rb
acfs-0.40.0 lib/acfs/model/attributes/boolean.rb
acfs-0.39.1 lib/acfs/model/attributes/boolean.rb
acfs-0.39.0 lib/acfs/model/attributes/boolean.rb
acfs-0.38.0 lib/acfs/model/attributes/boolean.rb
acfs-0.37.0.1.b295 lib/acfs/model/attributes/boolean.rb
acfs-0.37.0 lib/acfs/model/attributes/boolean.rb
acfs-0.36.0.1.b293 lib/acfs/model/attributes/boolean.rb
acfs-0.36.0 lib/acfs/model/attributes/boolean.rb
acfs-0.35.0.1.b291 lib/acfs/model/attributes/boolean.rb
acfs-0.35.0 lib/acfs/model/attributes/boolean.rb
acfs-0.34.1.1.b289 lib/acfs/model/attributes/boolean.rb
acfs-0.34.1 lib/acfs/model/attributes/boolean.rb
acfs-0.34.0.1.b288 lib/acfs/model/attributes/boolean.rb
acfs-0.34.0.1.b287 lib/acfs/model/attributes/boolean.rb
acfs-0.34.0.1.b286 lib/acfs/model/attributes/boolean.rb