Sha256: 17c9b4ddb9009d447b390d40bc9e1c96021acdde999c1304598c1597671fbf3a

Contents?: true

Size: 639 Bytes

Versions: 117

Compression:

Stored size: 639 Bytes

Contents

module CassandraObject
  module Types
    module BooleanType
      TRUE_VALS = [true, 'true', '1']
      FALSE_VALS = [false, 'false', '0', '', nil]
      VALID_VALS = TRUE_VALS + FALSE_VALS
      
      def encode(bool)
        unless VALID_VALS.include?(bool)
          raise ArgumentError.new("#{self} requires a boolean")
        end
        TRUE_VALS.include?(bool) ? '1' : '0'
      end
      module_function :encode

      def decode(str)
        raise ArgumentError.new("Cannot convert #{str} into a boolean") unless VALID_VALS.include?(str)
        TRUE_VALS.include?(str)
      end
      module_function :decode
    end
  end
end

Version data entries

117 entries across 117 versions & 2 rubygems

Version Path
sessionm-cassandra_object-2.3.9 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.8 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.6 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.5 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.4 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.3 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.2 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.1 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.3.0 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.55 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.54 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.53 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.52 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.51 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.50 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.49 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.48 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.47 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.46 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.45 lib/cassandra_object/types/boolean_type.rb