Sha256: 93259e23967c553ad4f4417a98223dbd00f1d9bdba9302ef33f363af8e8c939d

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

class Cassandra
  module Helpers
    def extract_and_validate_params(column_family, keys, args, options)
      options = options.dup
      column_family = column_family.to_s
      # Keys
      [keys].flatten.each do |key|
        raise ArgumentError, "Key #{key.inspect} must be a String for #{caller[2].inspect}." unless key.is_a?(String)
      end

      # Options
      if args.last.is_a?(Hash)
        extras = args.last.keys - options.keys
        raise ArgumentError, "Invalid options #{extras.inspect[1..-2]} for #{caller[1]}" if extras.any?
        options.merge!(args.pop)      
      end

      # Ranges
      column, sub_column = args[0], args[1]
      raise ArgumentError, "Invalid arguments: subcolumns specified for a non-supercolumn family" if sub_column && !is_super(column_family)      
      klass, sub_klass = column_name_class(column_family), sub_column_name_class(column_family)
      range_class = column ? sub_klass : klass

      [:start, :finish].each do |opt|
        options[opt] = options[opt] ? range_class.new(options[opt]).to_s : ''
      end

      [column_family, s_map(column, klass), s_map(sub_column, sub_klass), options]
    end

    # Convert stuff to strings.
    def s_map(el, klass)
      case el
      when Array then el.map { |i| s_map(i, klass) }
      when NilClass then nil
      else
        klass.new(el).to_s
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 5 rubygems

Version Path
sessionm-cassandra-1.1.2 lib/cassandra/helpers.rb
sessionm-cassandra-1.1.1 lib/cassandra/helpers.rb
sessionm-cassandra-1.1.0 lib/cassandra/helpers.rb
cassandra-0.23.0 lib/cassandra/helpers.rb
cassandra-0.22.0 lib/cassandra/helpers.rb
cassandra-mavericks-0.21.1 lib/cassandra/helpers.rb
cassandra-0.21.0 lib/cassandra/helpers.rb
cassandra-0.20.0 lib/cassandra/helpers.rb
cassandra-0.19.0 lib/cassandra/helpers.rb
sessionm-cassandra-1.0.2 lib/cassandra/helpers.rb
cassandra-0.18.0 lib/cassandra/helpers.rb
sessionm-cassandra-1.0.1 lib/cassandra/helpers.rb
sessionm-cassandra-1.0.0 lib/cassandra/helpers.rb
cassandra-0.17.0 lib/cassandra/helpers.rb
cassandra-0.16.0 lib/cassandra/helpers.rb
cassandra-0.15.0 lib/cassandra/helpers.rb
cassandra-0.14.0 lib/cassandra/helpers.rb
cassandra-0.13.0 lib/cassandra/helpers.rb
hallelujah-cassandra-0.12.3 lib/cassandra/helpers.rb
mcmire-cassandra-0.12.3 lib/cassandra/helpers.rb