Sha256: 94be92550e5dfd03252142ebcd862bbe8fcd97bdb3fdaafcfb7c67ebf83a900f
Contents?: true
Size: 1.82 KB
Versions: 3
Compression:
Stored size: 1.82 KB
Contents
=begin Copyright 2011 Inside Systems, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =end module CassandraCQL class Row attr_reader :row def initialize(row, schema) @row, @schema = row, schema @value_cache = Hash.new { |h, key| # If it's a number and not one of our columns, assume it's an index if key.kind_of?(Fixnum) and !column_names.include?(key) column_name = column_names[key] column_index = key else column_name = key column_index = column_names.index(key) end if column_index.nil? # Cache negative hits h[column_name] = nil else h[column_name] = ColumnFamily.cast(@row.columns[column_index].value, @schema.values[@row.columns[column_index].name]) end } end def [](obj) @value_cache[obj] end def column_names @names ||= @row.columns.map do |column| ColumnFamily.cast(column.name, @schema.names[column.name]) end end def column_values @row.columns.map { |column| @value_cache[column.name] } end def columns @row.columns.size end def to_a column_values end # TODO: This should be an ordered hash def to_hash Hash[([column_names, column_values]).transpose] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
cassandra-cql-1.1.2 | lib/cassandra-cql/row.rb |
cassandra-cql-1.1.1 | lib/cassandra-cql/row.rb |
cassandra-cql-1.1.0 | lib/cassandra-cql/row.rb |