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.30.0.1.b260 lib/acfs/model/attributes/boolean.rb
acfs-0.30.0 lib/acfs/model/attributes/boolean.rb
acfs-0.29.1.1.b259 lib/acfs/model/attributes/boolean.rb
acfs-0.29.1.1.b257 lib/acfs/model/attributes/boolean.rb
acfs-0.29.1 lib/acfs/model/attributes/boolean.rb
acfs-0.29.0.1.b256 lib/acfs/model/attributes/boolean.rb
acfs-0.29.0.1.b254 lib/acfs/model/attributes/boolean.rb
acfs-0.29.0 lib/acfs/model/attributes/boolean.rb
acfs-0.28.0.1.b253 lib/acfs/model/attributes/boolean.rb
acfs-0.28.0.1.b249 lib/acfs/model/attributes/boolean.rb
acfs-0.28.0 lib/acfs/model/attributes/boolean.rb
acfs-0.27.0.1.b248 lib/acfs/model/attributes/boolean.rb
acfs-0.27.0.1.b244 lib/acfs/model/attributes/boolean.rb
acfs-0.27.0 lib/acfs/model/attributes/boolean.rb
acfs-0.26.0.1.b243 lib/acfs/model/attributes/boolean.rb
acfs-0.26.0.1.b242 lib/acfs/model/attributes/boolean.rb
acfs-0.26.0 lib/acfs/model/attributes/boolean.rb
acfs-0.25.0.1.b232 lib/acfs/model/attributes/boolean.rb
acfs-0.25.0.1.b229 lib/acfs/model/attributes/boolean.rb
acfs-0.25.0.1.b228 lib/acfs/model/attributes/boolean.rb