Sha256: ab9629c2c2ca6f1217501b331d3f13bacc2beb85d7d1c8d529a9f9ef3d2bff07

Contents?: true

Size: 834 Bytes

Versions: 24

Compression:

Stored size: 834 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
    #
    module Boolean

      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 self.cast(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

24 entries across 24 versions & 1 rubygems

Version Path
acfs-0.22.2.b193 lib/acfs/model/attributes/boolean.rb
acfs-0.22.2 lib/acfs/model/attributes/boolean.rb
acfs-0.22.1.b192 lib/acfs/model/attributes/boolean.rb
acfs-0.22.1 lib/acfs/model/attributes/boolean.rb
acfs-0.22.0.b191 lib/acfs/model/attributes/boolean.rb
acfs-0.22.0.b190 lib/acfs/model/attributes/boolean.rb
acfs-0.22.0 lib/acfs/model/attributes/boolean.rb
acfs-0.21.1.b189 lib/acfs/model/attributes/boolean.rb
acfs-0.21.1.rc1.b188 lib/acfs/model/attributes/boolean.rb
acfs-0.21.1 lib/acfs/model/attributes/boolean.rb
acfs-0.21.0.rc1.b187 lib/acfs/model/attributes/boolean.rb
acfs-0.21.1.rc1 lib/acfs/model/attributes/boolean.rb
acfs-0.21.0.rc1 lib/acfs/model/attributes/boolean.rb
acfs-0.22.0.rc1.b186 lib/acfs/model/attributes/boolean.rb
acfs-0.21.0.b185 lib/acfs/model/attributes/boolean.rb
acfs-0.20.0.dev.b184 lib/acfs/model/attributes/boolean.rb
acfs-0.21.0 lib/acfs/model/attributes/boolean.rb
acfs-0.20.0.dev.b183 lib/acfs/model/attributes/boolean.rb
acfs-0.20.0.dev.b182 lib/acfs/model/attributes/boolean.rb
acfs-0.20.0.dev.b181 lib/acfs/model/attributes/boolean.rb