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-4.0.32 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.31 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.30 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.29 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.28 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.27 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.26 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.25 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.24 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.23 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.22 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.21 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.20 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.7.5 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.7.4 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.18 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.17 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.16 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.15 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-4.0.14 lib/cassandra_object/types/boolean_type.rb