cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +90 -38
  3. data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
  4. data/lib/cassandra.rb +327 -130
  5. data/lib/cassandra/address_resolution.rb +1 -1
  6. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
  7. data/lib/cassandra/address_resolution/policies/none.rb +1 -1
  8. data/lib/cassandra/aggregate.rb +21 -7
  9. data/lib/cassandra/argument.rb +2 -2
  10. data/lib/cassandra/auth.rb +4 -4
  11. data/lib/cassandra/auth/providers.rb +1 -1
  12. data/lib/cassandra/auth/providers/password.rb +9 -5
  13. data/lib/cassandra/cassandra_logger.rb +80 -0
  14. data/lib/cassandra/cluster.rb +38 -9
  15. data/lib/cassandra/cluster/client.rb +801 -205
  16. data/lib/cassandra/cluster/connection_pool.rb +2 -2
  17. data/lib/cassandra/cluster/connector.rb +74 -25
  18. data/lib/cassandra/cluster/control_connection.rb +217 -82
  19. data/lib/cassandra/cluster/failed_connection.rb +1 -1
  20. data/lib/cassandra/cluster/metadata.rb +12 -4
  21. data/lib/cassandra/cluster/options.rb +60 -11
  22. data/lib/cassandra/cluster/registry.rb +69 -16
  23. data/lib/cassandra/cluster/schema.rb +25 -7
  24. data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
  25. data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
  26. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
  27. data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
  28. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
  29. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
  30. data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
  31. data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
  32. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
  33. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
  34. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
  35. data/lib/cassandra/column.rb +3 -3
  36. data/lib/cassandra/compression.rb +1 -1
  37. data/lib/cassandra/compression/compressors/lz4.rb +4 -3
  38. data/lib/cassandra/compression/compressors/snappy.rb +4 -3
  39. data/lib/cassandra/driver.rb +103 -41
  40. data/lib/cassandra/errors.rb +265 -30
  41. data/lib/cassandra/execution/info.rb +16 -5
  42. data/lib/cassandra/execution/options.rb +99 -54
  43. data/lib/cassandra/execution/trace.rb +16 -9
  44. data/lib/cassandra/executors.rb +1 -1
  45. data/lib/cassandra/function.rb +19 -13
  46. data/lib/cassandra/function_collection.rb +85 -0
  47. data/lib/cassandra/future.rb +106 -48
  48. data/lib/cassandra/host.rb +10 -4
  49. data/lib/cassandra/keyspace.rb +90 -33
  50. data/lib/cassandra/listener.rb +1 -1
  51. data/lib/cassandra/load_balancing.rb +2 -2
  52. data/lib/cassandra/load_balancing/policies.rb +1 -1
  53. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +18 -18
  54. data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
  55. data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
  56. data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
  57. data/lib/cassandra/null_logger.rb +27 -6
  58. data/lib/cassandra/protocol.rb +1 -1
  59. data/lib/cassandra/protocol/coder.rb +78 -39
  60. data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
  61. data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
  62. data/lib/cassandra/protocol/request.rb +2 -2
  63. data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
  64. data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
  65. data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
  66. data/lib/cassandra/protocol/requests/execute_request.rb +41 -20
  67. data/lib/cassandra/protocol/requests/options_request.rb +1 -1
  68. data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
  69. data/lib/cassandra/protocol/requests/query_request.rb +27 -22
  70. data/lib/cassandra/protocol/requests/register_request.rb +2 -2
  71. data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
  72. data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
  73. data/lib/cassandra/protocol/response.rb +2 -2
  74. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
  75. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
  76. data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
  77. data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
  78. data/lib/cassandra/protocol/responses/error_response.rb +101 -13
  79. data/lib/cassandra/protocol/responses/event_response.rb +1 -1
  80. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
  81. data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
  82. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
  83. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
  84. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
  85. data/lib/cassandra/protocol/responses/ready_response.rb +3 -3
  86. data/lib/cassandra/protocol/responses/result_response.rb +4 -2
  87. data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
  88. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
  89. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
  90. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
  91. data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
  92. data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
  93. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
  94. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
  95. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
  96. data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
  97. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
  98. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
  99. data/lib/cassandra/protocol/v1.rb +101 -36
  100. data/lib/cassandra/protocol/v3.rb +124 -51
  101. data/lib/cassandra/protocol/v4.rb +172 -68
  102. data/lib/cassandra/reconnection.rb +1 -1
  103. data/lib/cassandra/reconnection/policies.rb +1 -1
  104. data/lib/cassandra/reconnection/policies/constant.rb +2 -4
  105. data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
  106. data/lib/cassandra/result.rb +53 -19
  107. data/lib/cassandra/retry.rb +8 -8
  108. data/lib/cassandra/retry/policies.rb +1 -1
  109. data/lib/cassandra/retry/policies/default.rb +1 -1
  110. data/lib/cassandra/retry/policies/downgrading_consistency.rb +7 -3
  111. data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
  112. data/lib/cassandra/session.rb +22 -16
  113. data/lib/cassandra/statement.rb +1 -1
  114. data/lib/cassandra/statements.rb +1 -1
  115. data/lib/cassandra/statements/batch.rb +16 -10
  116. data/lib/cassandra/statements/bound.rb +10 -3
  117. data/lib/cassandra/statements/prepared.rb +59 -15
  118. data/lib/cassandra/statements/simple.rb +23 -10
  119. data/lib/cassandra/statements/void.rb +1 -1
  120. data/lib/cassandra/table.rb +79 -30
  121. data/lib/cassandra/time.rb +11 -6
  122. data/lib/cassandra/time_uuid.rb +7 -7
  123. data/lib/cassandra/tuple.rb +16 -8
  124. data/lib/cassandra/types.rb +20 -9
  125. data/lib/cassandra/udt.rb +32 -36
  126. data/lib/cassandra/util.rb +20 -13
  127. data/lib/cassandra/uuid.rb +22 -15
  128. data/lib/cassandra/uuid/generator.rb +7 -5
  129. data/lib/cassandra/version.rb +2 -2
  130. data/lib/datastax/cassandra.rb +1 -1
  131. metadata +5 -3
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -48,21 +48,27 @@ module Cassandra
48
48
  #
49
49
  # @raise [ArgumentError] if cql statement given is not a String
50
50
  def initialize(cql, params = nil, type_hints = nil, idempotent = false)
51
- Util.assert_instance_of(::String, cql) { "cql must be a string, #{cql.inspect} given" }
51
+ Util.assert_instance_of(::String, cql) do
52
+ "cql must be a string, #{cql.inspect} given"
53
+ end
52
54
 
53
55
  params ||= EMPTY_LIST
54
56
 
55
57
  if params.is_a?(::Hash)
56
58
  params_names = []
57
- params = params.each_with_object([]) do |(name, value), params|
59
+ params = params.each_with_object([]) do |(name, value), collector|
58
60
  params_names << name
59
- params << value
61
+ collector << value
60
62
  end
61
63
  if type_hints && !type_hints.empty?
62
- Util.assert_instance_of(::Hash, type_hints) { "type_hints must be a Hash when using named params" }
64
+ Util.assert_instance_of(::Hash, type_hints) do
65
+ 'type_hints must be a Hash when using named params'
66
+ end
63
67
  end
64
68
  else
65
- Util.assert_instance_of(::Array, params) { "params must be an Array or a Hash, #{params.inspect} given" }
69
+ Util.assert_instance_of(::Array, params) do
70
+ "params must be an Array or a Hash, #{params.inspect} given"
71
+ end
66
72
  params_names = EMPTY_LIST
67
73
  end
68
74
 
@@ -71,19 +77,26 @@ module Cassandra
71
77
  if type_hints.is_a?(::Hash)
72
78
  type_hints = params_names.map {|name| type_hints[name] }
73
79
  else
74
- Util.assert_instance_of(::Array, type_hints) { "type_hints must be an Array or a Hash, #{type_hints.inspect} given" }
80
+ Util.assert_instance_of(::Array, type_hints) do
81
+ "type_hints must be an Array or a Hash, #{type_hints.inspect} given"
82
+ end
75
83
  end
76
84
 
77
85
  @cql = cql
78
86
  @params = params
79
- @params_types = params.each_with_index.map {|value, index| (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ? type_hints[index] : Util.guess_type(value)}
87
+ @params_types = params.each_with_index.map do |value, index|
88
+ (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ?
89
+ type_hints[index] :
90
+ Util.guess_type(value)
91
+ end
80
92
  @params_names = params_names
81
93
  @idempotent = idempotent
82
94
  end
83
95
 
84
96
  # @return [String] a CLI-friendly simple statement representation
85
97
  def inspect
86
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @cql=#{@cql.inspect} @params=#{@params.inspect}>"
98
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \
99
+ "@params=#{@params.inspect}>"
87
100
  end
88
101
 
89
102
  # @param other [Object, Cassandra::Statements::Simple] object to compare
@@ -94,7 +107,7 @@ module Cassandra
94
107
  @params == other.params
95
108
  end
96
109
 
97
- alias :== :eql?
110
+ alias == eql?
98
111
  end
99
112
  end
100
113
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -30,12 +30,23 @@ module Cassandra
30
30
  :replicate_on_write, :compaction_strategy, :compact_storage,
31
31
  :compression_parameters
32
32
 
33
- def initialize(comment, read_repair_chance, local_read_repair_chance,
34
- gc_grace_seconds, caching, bloom_filter_fp_chance,
35
- populate_io_cache_on_flush, memtable_flush_period_in_ms,
36
- default_time_to_live, speculative_retry, index_interval,
37
- replicate_on_write, min_index_interval, max_index_interval,
38
- compaction_strategy, compression_parameters, compact_storage)
33
+ def initialize(comment,
34
+ read_repair_chance,
35
+ local_read_repair_chance,
36
+ gc_grace_seconds,
37
+ caching,
38
+ bloom_filter_fp_chance,
39
+ populate_io_cache_on_flush,
40
+ memtable_flush_period_in_ms,
41
+ default_time_to_live,
42
+ speculative_retry,
43
+ index_interval,
44
+ replicate_on_write,
45
+ min_index_interval,
46
+ max_index_interval,
47
+ compaction_strategy,
48
+ compression_parameters,
49
+ compact_storage)
39
50
  @comment = comment
40
51
  @read_repair_chance = read_repair_chance
41
52
  @local_read_repair_chance = local_read_repair_chance
@@ -71,22 +82,53 @@ module Cassandra
71
82
  options = []
72
83
 
73
84
  options << 'COMPACT STORAGE' if @compact_storage
74
- options << "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}" unless @bloom_filter_fp_chance.nil?
85
+ unless @bloom_filter_fp_chance.nil?
86
+ options <<
87
+ "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}"
88
+ end
75
89
  options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
76
90
  options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
77
- options << "compaction = #{@compaction_strategy.to_cql}" unless @compaction_strategy.nil?
78
- options << "compression = #{Util.encode_object(@compression_parameters)}" unless @compression_parameters.nil?
79
- options << "dclocal_read_repair_chance = #{Util.encode_object(@local_read_repair_chance)}" unless @local_read_repair_chance.nil?
80
- options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}" unless @default_time_to_live.nil?
81
- options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}" unless @gc_grace_seconds.nil?
82
- options << "index_interval = #{Util.encode_object(@index_interval)}" unless @index_interval.nil?
83
- options << "max_index_interval = #{Util.encode_object(@max_index_interval)}" unless @max_index_interval.nil?
84
- options << "memtable_flush_period_in_ms = #{Util.encode_object(@memtable_flush_period_in_ms)}" unless @memtable_flush_period_in_ms.nil?
85
- options << "min_index_interval = #{Util.encode_object(@min_index_interval)}" unless @min_index_interval.nil?
86
- options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'" unless @populate_io_cache_on_flush.nil?
87
- options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}" unless @read_repair_chance.nil?
88
- options << "replicate_on_write = '#{@replicate_on_write}'" unless @replicate_on_write.nil?
89
- options << "speculative_retry = #{Util.encode_object(@speculative_retry)}" unless @speculative_retry.nil?
91
+ unless @compaction_strategy.nil?
92
+ options << "compaction = #{@compaction_strategy.to_cql}"
93
+ end
94
+ unless @compression_parameters.nil?
95
+ options << "compression = #{Util.encode_object(@compression_parameters)}"
96
+ end
97
+ unless @local_read_repair_chance.nil?
98
+ options << 'dclocal_read_repair_chance = ' \
99
+ "#{Util.encode_object(@local_read_repair_chance)}"
100
+ end
101
+ unless @default_time_to_live.nil?
102
+ options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}"
103
+ end
104
+ unless @gc_grace_seconds.nil?
105
+ options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}"
106
+ end
107
+ unless @index_interval.nil?
108
+ options << "index_interval = #{Util.encode_object(@index_interval)}"
109
+ end
110
+ unless @max_index_interval.nil?
111
+ options << "max_index_interval = #{Util.encode_object(@max_index_interval)}"
112
+ end
113
+ unless @memtable_flush_period_in_ms.nil?
114
+ options << 'memtable_flush_period_in_ms = ' \
115
+ "#{Util.encode_object(@memtable_flush_period_in_ms)}"
116
+ end
117
+ unless @min_index_interval.nil?
118
+ options << "min_index_interval = #{Util.encode_object(@min_index_interval)}"
119
+ end
120
+ unless @populate_io_cache_on_flush.nil?
121
+ options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'"
122
+ end
123
+ unless @read_repair_chance.nil?
124
+ options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}"
125
+ end
126
+ unless @replicate_on_write.nil?
127
+ options << "replicate_on_write = '#{@replicate_on_write}'"
128
+ end
129
+ unless @speculative_retry.nil?
130
+ options << "speculative_retry = #{Util.encode_object(@speculative_retry)}"
131
+ end
90
132
 
91
133
  options.join("\nAND ")
92
134
  end
@@ -109,7 +151,7 @@ module Cassandra
109
151
  @compression_parameters == other.compression_parameters &&
110
152
  @compact_storage == other.compact_storage
111
153
  end
112
- alias :== :eql?
154
+ alias == eql?
113
155
  end
114
156
 
115
157
  # @private
@@ -133,7 +175,7 @@ module Cassandra
133
175
  @klass == other.klass &&
134
176
  @options == other.options
135
177
  end
136
- alias :== :eql?
178
+ alias == eql?
137
179
  end
138
180
 
139
181
  # @private
@@ -146,7 +188,13 @@ module Cassandra
146
188
  attr_reader :partition_key
147
189
 
148
190
  # @private
149
- def initialize(keyspace, name, partition_key, clustering_columns, columns, options, clustering_order)
191
+ def initialize(keyspace,
192
+ name,
193
+ partition_key,
194
+ clustering_columns,
195
+ columns,
196
+ options,
197
+ clustering_order)
150
198
  @keyspace = keyspace
151
199
  @name = name
152
200
  @partition_key = partition_key
@@ -159,7 +207,7 @@ module Cassandra
159
207
  # @param name [String] column name
160
208
  # @return [Boolean] whether this table has a given column
161
209
  def has_column?(name)
162
- @columns.has_key?(name)
210
+ @columns.key?(name)
163
211
  end
164
212
 
165
213
  # @param name [String] column name
@@ -182,7 +230,7 @@ module Cassandra
182
230
  @columns.values
183
231
  end
184
232
  end
185
- alias :columns :each_column
233
+ alias columns each_column
186
234
 
187
235
  # @return [String] a cql representation of this table
188
236
  def to_cql
@@ -229,7 +277,7 @@ module Cassandra
229
277
  cql << "\n)\nWITH "
230
278
 
231
279
  if @clustering_order.any? {|o| o != :asc}
232
- cql << "CLUSTERING ORDER BY ("
280
+ cql << 'CLUSTERING ORDER BY ('
233
281
  first = true
234
282
  @clustering_columns.zip(@clustering_order) do |column, order|
235
283
  if first
@@ -249,7 +297,8 @@ module Cassandra
249
297
 
250
298
  # @private
251
299
  def inspect
252
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @keyspace=#{@keyspace} @name=#{@name}>"
300
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} " \
301
+ "@keyspace=#{@keyspace} @name=#{@name}>"
253
302
  end
254
303
 
255
304
  # @private
@@ -263,7 +312,7 @@ module Cassandra
263
312
  @options == other.options &&
264
313
  @clustering_order == other.clustering_order
265
314
  end
266
- alias :== :eql?
315
+ alias == eql?
267
316
 
268
317
  private
269
318
 
@@ -282,7 +331,7 @@ module Cassandra
282
331
  if is_frozen
283
332
  "frozen <#{type}>"
284
333
  else
285
- "#{type}"
334
+ type.to_s
286
335
  end
287
336
  end
288
337
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ module Cassandra
35
35
  # @private
36
36
  def initialize(nanoseconds = 0)
37
37
  if nanoseconds < 0 && nanoseconds > NANOSECONDS_IN_DAY - 1
38
- raise ::ArgumentError, "value must be between 0 and " \
38
+ raise ::ArgumentError, 'value must be between 0 and ' \
39
39
  "#{NANOSECONDS_IN_DAY}, #{value.inspect} given"
40
40
  end
41
41
 
@@ -57,18 +57,23 @@ module Cassandra
57
57
  # @return [Integer] an integer between 0 and 60, the number of full seconds
58
58
  # since the last full minutes that this time represents
59
59
  def seconds
60
- (@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
60
+ (@nanoseconds -
61
+ (hours * NANOSECONDS_IN_HOUR) -
62
+ (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
61
63
  end
62
64
 
63
65
  # @return [Integer] an integer between 0 and 60, the number of full
64
66
  # miliseconds since the last full second that this time represents
65
67
  def miliseconds
66
- (@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE) - (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
68
+ (@nanoseconds -
69
+ (hours * NANOSECONDS_IN_HOUR) -
70
+ (minutes * NANOSECONDS_IN_MINUTE) -
71
+ (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
67
72
  end
68
73
 
69
74
  # @return [String] a "%H:%M%S.%3N" formatted time string
70
75
  def to_s
71
- '%.2d:%.2d:%.2d.%.3d' % [hours, minutes, seconds, miliseconds]
76
+ format('%.2d:%.2d:%.2d.%.3d', hours, minutes, seconds, miliseconds)
72
77
  end
73
78
 
74
79
  # @return [Integer] an integer between 0 and 86400000000000, the number of
@@ -81,7 +86,7 @@ module Cassandra
81
86
  def eql?(other)
82
87
  other.is_a?(Time) && other.to_nanoseconds == @nanoseconds
83
88
  end
84
- alias :== :eql?
89
+ alias == eql?
85
90
 
86
91
  # @private
87
92
  def <=>(other)
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -28,8 +28,8 @@ module Cassandra
28
28
  # @return [Time]
29
29
  def to_time
30
30
  t = time_bits - GREGORIAN_OFFSET
31
- seconds = t/10_000_000
32
- microseconds = (t - seconds * 10_000_000)/10.0
31
+ seconds = t / 10_000_000
32
+ microseconds = (t - seconds * 10_000_000) / 10.0
33
33
 
34
34
  ::Time.at(seconds, microseconds).utc
35
35
  end
@@ -52,10 +52,10 @@ module Cassandra
52
52
  # @return [Integer] `-1` when less than `other`, `0` when equal to `other`
53
53
  # and `1` when greater than `other`
54
54
  def <=>(other)
55
- return nil unless other.kind_of?(Cassandra::Uuid)
56
- c = self.value <=> other.value
55
+ return nil unless other.is_a?(Cassandra::Uuid)
56
+ c = value <=> other.value
57
57
  return c if c == 0 || !other.is_a?(Cassandra::TimeUuid)
58
- self.time_bits <=> other.time_bits
58
+ time_bits <=> other.time_bits
59
59
  end
60
60
 
61
61
  protected
@@ -77,4 +77,4 @@ module Cassandra
77
77
  # @private
78
78
  GREGORIAN_OFFSET = 122192928000000000
79
79
  end
80
- end
80
+ end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -40,12 +40,16 @@ module Cassandra
40
40
 
41
41
  def fetch(i)
42
42
  i = Integer(i)
43
- raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}" if i < 0 || i >= @types.size
43
+ if i < 0 || i >= @types.size
44
+ raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}"
45
+ end
44
46
  @values[i]
45
47
  end
46
48
 
47
49
  def []=(i, value)
48
- raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}" if i < 0 || i >= @types.size
50
+ if i < 0 || i >= @types.size
51
+ raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}"
52
+ end
49
53
  Util.assert_type(@types[i], value)
50
54
  @values[i] = value
51
55
  end
@@ -55,7 +59,7 @@ module Cassandra
55
59
  end
56
60
 
57
61
  def inspect
58
- "#<Cassandra::Tuple:0x#{self.object_id.to_s(16)} #{to_s}>"
62
+ "#<Cassandra::Tuple:0x#{object_id.to_s(16)} #{self}>"
59
63
  end
60
64
  end
61
65
 
@@ -86,7 +90,9 @@ module Cassandra
86
90
  # @return [Object] value of the tuple at position `i`
87
91
  def fetch(i)
88
92
  i = Integer(i)
89
- raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}" if i < 0 || i >= @values.size
93
+ if i < 0 || i >= @values.size
94
+ raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}"
95
+ end
90
96
  @values[i]
91
97
  end
92
98
 
@@ -97,7 +103,9 @@ module Cassandra
97
103
  # @return [Object] value of the tuple at position `i`
98
104
  def []=(i, value)
99
105
  i = Integer(i)
100
- raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}" if i < 0 || i >= @values.size
106
+ if i < 0 || i >= @values.size
107
+ raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}"
108
+ end
101
109
  @values[i] = value
102
110
  end
103
111
 
@@ -114,14 +122,14 @@ module Cassandra
114
122
 
115
123
  # @private
116
124
  def inspect
117
- "#<Cassandra::Tuple:0x#{self.object_id.to_s(16)} #{to_s}>"
125
+ "#<Cassandra::Tuple:0x#{object_id.to_s(16)} #{self}>"
118
126
  end
119
127
 
120
128
  # @private
121
129
  def eql?(other)
122
130
  other == @values
123
131
  end
124
- alias :== :eql?
132
+ alias == eql?
125
133
 
126
134
  # @private
127
135
  def hash
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -144,7 +144,10 @@ module Cassandra
144
144
  end
145
145
 
146
146
  def assert_boolean(value, message, &block)
147
- Util.assert_instance_of_one_of([::TrueClass, ::FalseClass], value, message, &block)
147
+ Util.assert_instance_of_one_of([::TrueClass, ::FalseClass],
148
+ value,
149
+ message,
150
+ &block)
148
151
  end
149
152
 
150
153
  def new_decimal(value)
@@ -193,7 +196,7 @@ module Cassandra
193
196
  Util.assert_instance_of(::Time, value, message, &block)
194
197
  end
195
198
 
196
- def new_uuid(value, message, &block)
199
+ def new_uuid(value)
197
200
  Cassandra::Uuid.new(value)
198
201
  end
199
202
 
@@ -1042,7 +1045,9 @@ module Cassandra
1042
1045
  #
1043
1046
  # tuple(varchar, varchar, int).new('Jane', 'Smith', 38) # => (Jane, Smith, 38)
1044
1047
  def new(*values)
1045
- Util.assert(values.size <= @members.size) { "too many values: #{values.size} out of max #{@members.size}" }
1048
+ Util.assert(values.size <= @members.size) do
1049
+ "too many values: #{values.size} out of max #{@members.size}"
1050
+ end
1046
1051
  values.each_with_index do |v, i|
1047
1052
  Util.assert_type(@members[i], v)
1048
1053
  end
@@ -1240,7 +1245,9 @@ module Cassandra
1240
1245
  value = value.first if value.one?
1241
1246
  value = Array(value) unless value.is_a?(::Hash)
1242
1247
 
1243
- Util.assert(value.size <= @fields.size) { "too many values: #{value.size} out of #{@fields.size}" }
1248
+ Util.assert(value.size <= @fields.size) do
1249
+ "too many values: #{value.size} out of #{@fields.size}"
1250
+ end
1244
1251
 
1245
1252
  case value
1246
1253
  when ::Array
@@ -1282,7 +1289,8 @@ module Cassandra
1282
1289
  # @return [String] `"keyspace.name"`
1283
1290
  # @see Cassandra::Type#to_s
1284
1291
  def to_s
1285
- "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} {#{@fields.join(', ')}}"
1292
+ "#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} " \
1293
+ "{#{@fields.join(', ')}}"
1286
1294
  end
1287
1295
 
1288
1296
  def hash
@@ -1306,7 +1314,8 @@ module Cassandra
1306
1314
 
1307
1315
  # Output this type in CQL
1308
1316
  def to_cql
1309
- cql = "CREATE TYPE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} (\n"
1317
+ cql = "CREATE TYPE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} " \
1318
+ "(\n"
1310
1319
  first = true
1311
1320
 
1312
1321
  @fields.each do |field|
@@ -1355,7 +1364,8 @@ module Cassandra
1355
1364
  # @param value [*Object] value to be coerced
1356
1365
  # @return [Object] a value of this type
1357
1366
  def new(*value)
1358
- raise ::NotImplementedError, "unable to create a value for custom type: #{@name.inspect}"
1367
+ raise ::NotImplementedError,
1368
+ "unable to create a value for custom type: #{@name.inspect}"
1359
1369
  end
1360
1370
 
1361
1371
  # Asserts that a given value is of this type
@@ -1365,7 +1375,8 @@ module Cassandra
1365
1375
  # @raise [ArgumentError] if the value is invalid
1366
1376
  # @return [void]
1367
1377
  def assert(value, message = nil, &block)
1368
- raise ::NotImplementedError, "unable to assert a value for custom type: #{@name.inspect}"
1378
+ raise ::NotImplementedError,
1379
+ "unable to assert a value for custom type: #{@name.inspect}"
1369
1380
  end
1370
1381
 
1371
1382
  # @return [String] a cassandra representation of this type