Module: Cassandra::Helpers
Instance Method Summary collapse
- #extract_and_validate_params(column_family, keys, args, options) ⇒ Object
-
#s_map(el, klass) ⇒ Object
Convert stuff to strings.
Instance Method Details
#extract_and_validate_params(column_family, keys, args, options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cassandra/helpers.rb', line 3 def extract_and_validate_params(column_family, keys, args, ) = .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 - .keys raise ArgumentError, "Invalid options #{extras.inspect[1..-2]} for #{caller[1]}" if extras.any? .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| [opt] = [opt] ? ([opt] == '' ? '' : range_class.new([opt]).to_s) : '' end [column_family, s_map(column, klass), s_map(sub_column, sub_klass), ] end |
#s_map(el, klass) ⇒ Object
Convert stuff to strings.
32 33 34 35 36 37 38 39 |
# File 'lib/cassandra/helpers.rb', line 32 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 |