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.2.44 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.43 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.42 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.41 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.40 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.39 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.38 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.37 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.36 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.35 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.34 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.33 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.32 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.31 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.30 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.29 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.28 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.27 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.26 lib/cassandra_object/types/boolean_type.rb
sessionm-cassandra_object-2.2.24 lib/cassandra_object/types/boolean_type.rb