datastax_rails 2.0.12 → 2.0.15

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 (143) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +5 -5
  3. data/lib/blankslate.rb +8 -11
  4. data/lib/cql-rb_extensions.rb +5 -3
  5. data/lib/datastax_rails/associations/association.rb +93 -101
  6. data/lib/datastax_rails/associations/association_scope.rb +7 -7
  7. data/lib/datastax_rails/associations/belongs_to_association.rb +46 -48
  8. data/lib/datastax_rails/associations/builder/association.rb +32 -31
  9. data/lib/datastax_rails/associations/builder/belongs_to.rb +19 -20
  10. data/lib/datastax_rails/associations/builder/collection_association.rb +32 -32
  11. data/lib/datastax_rails/associations/builder/has_and_belongs_to_many.rb +21 -21
  12. data/lib/datastax_rails/associations/builder/has_many.rb +39 -40
  13. data/lib/datastax_rails/associations/builder/has_one.rb +30 -31
  14. data/lib/datastax_rails/associations/builder/singular_association.rb +31 -33
  15. data/lib/datastax_rails/associations/collection_association.rb +129 -135
  16. data/lib/datastax_rails/associations/collection_proxy.rb +21 -21
  17. data/lib/datastax_rails/associations/has_and_belongs_to_many_association.rb +26 -26
  18. data/lib/datastax_rails/associations/has_many_association.rb +38 -38
  19. data/lib/datastax_rails/associations/has_one_association.rb +31 -32
  20. data/lib/datastax_rails/associations/singular_association.rb +31 -30
  21. data/lib/datastax_rails/associations.rb +27 -24
  22. data/lib/datastax_rails/attribute_assignment.rb +17 -17
  23. data/lib/datastax_rails/attribute_methods/definition.rb +4 -4
  24. data/lib/datastax_rails/attribute_methods/dirty.rb +34 -33
  25. data/lib/datastax_rails/attribute_methods/primary_key.rb +3 -8
  26. data/lib/datastax_rails/attribute_methods/read.rb +10 -12
  27. data/lib/datastax_rails/attribute_methods/typecasting.rb +36 -35
  28. data/lib/datastax_rails/attribute_methods/write.rb +5 -6
  29. data/lib/datastax_rails/attribute_methods.rb +52 -56
  30. data/lib/datastax_rails/base.rb +122 -125
  31. data/lib/datastax_rails/callbacks.rb +15 -9
  32. data/lib/datastax_rails/cassandra_only_model.rb +6 -6
  33. data/lib/datastax_rails/collection.rb +5 -7
  34. data/lib/datastax_rails/column.rb +130 -118
  35. data/lib/datastax_rails/connection/statement_cache.rb +3 -3
  36. data/lib/datastax_rails/connection.rb +42 -33
  37. data/lib/datastax_rails/cql/alter_column_family.rb +19 -21
  38. data/lib/datastax_rails/cql/base.rb +8 -11
  39. data/lib/datastax_rails/cql/column_family.rb +11 -10
  40. data/lib/datastax_rails/cql/consistency.rb +2 -2
  41. data/lib/datastax_rails/cql/create_column_family.rb +15 -15
  42. data/lib/datastax_rails/cql/create_index.rb +5 -5
  43. data/lib/datastax_rails/cql/create_keyspace.rb +7 -7
  44. data/lib/datastax_rails/cql/delete.rb +16 -29
  45. data/lib/datastax_rails/cql/drop_column_family.rb +2 -2
  46. data/lib/datastax_rails/cql/drop_index.rb +2 -2
  47. data/lib/datastax_rails/cql/drop_keyspace.rb +2 -2
  48. data/lib/datastax_rails/cql/insert.rb +10 -16
  49. data/lib/datastax_rails/cql/select.rb +21 -33
  50. data/lib/datastax_rails/cql/truncate.rb +2 -2
  51. data/lib/datastax_rails/cql/update.rb +16 -24
  52. data/lib/datastax_rails/cql/use_keyspace.rb +2 -2
  53. data/lib/datastax_rails/cql.rb +2 -2
  54. data/lib/datastax_rails/dynamic_model.rb +32 -29
  55. data/lib/datastax_rails/errors.rb +6 -6
  56. data/lib/datastax_rails/grouped_collection.rb +3 -3
  57. data/lib/datastax_rails/inheritance.rb +9 -9
  58. data/lib/datastax_rails/payload_model.rb +24 -20
  59. data/lib/datastax_rails/persistence.rb +116 -110
  60. data/lib/datastax_rails/railtie.rb +7 -7
  61. data/lib/datastax_rails/reflection.rb +61 -59
  62. data/lib/datastax_rails/relation/batches.rb +12 -13
  63. data/lib/datastax_rails/relation/facet_methods.rb +44 -33
  64. data/lib/datastax_rails/relation/finder_methods.rb +95 -91
  65. data/lib/datastax_rails/relation/modification_methods.rb +5 -5
  66. data/lib/datastax_rails/relation/search_methods.rb +102 -102
  67. data/lib/datastax_rails/relation/spawn_methods.rb +25 -24
  68. data/lib/datastax_rails/relation/stats_methods.rb +9 -8
  69. data/lib/datastax_rails/relation.rb +165 -170
  70. data/lib/datastax_rails/rsolr_client_wrapper.rb +3 -3
  71. data/lib/datastax_rails/schema/cassandra.rb +44 -43
  72. data/lib/datastax_rails/schema/migrator.rb +52 -52
  73. data/lib/datastax_rails/schema/solr.rb +55 -47
  74. data/lib/datastax_rails/schema_cache.rb +1 -3
  75. data/lib/datastax_rails/scoping/default.rb +2 -3
  76. data/lib/datastax_rails/scoping/named.rb +3 -5
  77. data/lib/datastax_rails/scoping.rb +11 -12
  78. data/lib/datastax_rails/serialization.rb +34 -31
  79. data/lib/datastax_rails/serializers/xml_serializer.rb +178 -175
  80. data/lib/datastax_rails/timestamps.rb +4 -4
  81. data/lib/datastax_rails/types/dirty_collection.rb +57 -57
  82. data/lib/datastax_rails/types/dynamic_list.rb +1 -1
  83. data/lib/datastax_rails/types/dynamic_map.rb +5 -7
  84. data/lib/datastax_rails/types/dynamic_set.rb +2 -2
  85. data/lib/datastax_rails/util/solr_repair.rb +3 -3
  86. data/lib/datastax_rails/validations/associated.rb +8 -6
  87. data/lib/datastax_rails/validations/uniqueness.rb +8 -8
  88. data/lib/datastax_rails/validations.rb +9 -10
  89. data/lib/datastax_rails/version.rb +2 -1
  90. data/lib/datastax_rails/wide_storage_model.rb +6 -6
  91. data/lib/datastax_rails.rb +13 -9
  92. data/lib/schema_migration.rb +3 -3
  93. data/spec/datastax_rails/associations/belongs_to_association_spec.rb +2 -2
  94. data/spec/datastax_rails/associations/collection_association_spec.rb +14 -14
  95. data/spec/datastax_rails/associations/has_many_association_spec.rb +20 -20
  96. data/spec/datastax_rails/associations_spec.rb +11 -11
  97. data/spec/datastax_rails/attribute_methods_spec.rb +25 -25
  98. data/spec/datastax_rails/base_spec.rb +24 -24
  99. data/spec/datastax_rails/callbacks_spec.rb +21 -21
  100. data/spec/datastax_rails/column_spec.rb +133 -132
  101. data/spec/datastax_rails/connection/statement_cache_spec.rb +2 -2
  102. data/spec/datastax_rails/cql/base_spec.rb +4 -4
  103. data/spec/datastax_rails/cql/delete_spec.rb +19 -0
  104. data/spec/datastax_rails/cql/select_spec.rb +8 -8
  105. data/spec/datastax_rails/cql/update_spec.rb +8 -10
  106. data/spec/datastax_rails/dynamic_model_spec.rb +36 -22
  107. data/spec/datastax_rails/inheritance_spec.rb +11 -14
  108. data/spec/datastax_rails/persistence_spec.rb +73 -74
  109. data/spec/datastax_rails/relation/batches_spec.rb +13 -13
  110. data/spec/datastax_rails/relation/facet_methods_spec.rb +43 -35
  111. data/spec/datastax_rails/relation/finder_methods_spec.rb +77 -78
  112. data/spec/datastax_rails/relation/modification_methods_spec.rb +19 -19
  113. data/spec/datastax_rails/relation/search_methods_spec.rb +160 -160
  114. data/spec/datastax_rails/relation/spawn_methods_spec.rb +18 -18
  115. data/spec/datastax_rails/relation_spec.rb +119 -116
  116. data/spec/datastax_rails/schema/migrator_spec.rb +30 -30
  117. data/spec/datastax_rails/schema/solr_spec.rb +15 -15
  118. data/spec/datastax_rails/scoping/default_spec.rb +9 -9
  119. data/spec/datastax_rails/types/dynamic_list_spec.rb +12 -12
  120. data/spec/datastax_rails/types/dynamic_map_spec.rb +10 -10
  121. data/spec/datastax_rails/types/dynamic_set_spec.rb +22 -10
  122. data/spec/datastax_rails/validations/uniqueness_spec.rb +25 -25
  123. data/spec/datastax_rails/wide_storage_model_spec.rb +11 -0
  124. data/spec/datastax_rails_spec.rb +2 -2
  125. data/spec/dummy/config/application.rb +2 -3
  126. data/spec/dummy/config/boot.rb +1 -1
  127. data/spec/dummy/config/environments/development.rb +3 -3
  128. data/spec/dummy/config/environments/test.rb +1 -1
  129. data/spec/dummy/config/initializers/session_store.rb +1 -1
  130. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  131. data/spec/factories/audit_logs.rb +6 -0
  132. data/spec/factories/hobbies.rb +6 -0
  133. data/spec/factories/people.rb +5 -0
  134. data/spec/feature/dynamic_fields_spec.rb +4 -4
  135. data/spec/feature/overloaded_tables_spec.rb +11 -12
  136. data/spec/spec_helper.rb +17 -14
  137. data/spec/support/datastax_test_hook.rb +2 -2
  138. data/spec/support/default_consistency_shared_examples.rb +11 -11
  139. data/spec/support/models.rb +31 -32
  140. metadata +40 -6
  141. data/lib/datastax_rails/attribute_methods/before_type_cast.rb +0 -71
  142. data/lib/datastax_rails/log_subscriber.rb +0 -0
  143. data/spec/dummy/ks/migrate/20111117224534_models.rb +0 -20
@@ -10,31 +10,31 @@ module DatastaxRails
10
10
  'DatastaxRails::RecordNotFound' => :not_found,
11
11
  'DatastaxRails::RecordInvalid' => :unprocessable_entity,
12
12
  'DatastaxRails::RecordNotSaved' => :unprocessable_entity)
13
-
13
+
14
14
  initializer 'datastax_rails.init' do
15
15
  ActiveSupport.on_load(:datastax_rails) do
16
16
  end
17
- datastax_config = ERB.new(Rails.root.join('config',"datastax.yml").read).result(binding)
17
+ datastax_config = ERB.new(Rails.root.join('config', 'datastax.yml').read).result(binding)
18
18
  config = YAML.load(datastax_config)
19
19
  unless config[Rails.env]
20
- raise "ERROR: datastax.yml does not define a configuration for #{Rails.env} environment"
20
+ fail "ERROR: datastax.yml does not define a configuration for #{Rails.env} environment"
21
21
  end
22
22
  DatastaxRails::Base.establish_connection(config[Rails.env].with_indifferent_access)
23
23
  if defined?(PhusionPassenger)
24
24
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
25
25
  if forked
26
- DatastaxRails::Base.establish_connection(config[Rails.env].with_indifferent_access)
26
+ DatastaxRails::Base.establish_connection(config[Rails.env].with_indifferent_access)
27
27
  end
28
28
  end
29
29
  end
30
30
  end
31
-
31
+
32
32
  rake_tasks do
33
33
  load 'datastax_rails/tasks/ds.rake'
34
34
  end
35
-
35
+
36
36
  # generators do
37
- # require 'datastax_rails/generators/migration_generator'
37
+ # require 'datastax_rails/generators/migration_generator'
38
38
  # end
39
39
  end
40
40
  end
@@ -21,7 +21,7 @@ module DatastaxRails
21
21
  def create_reflection(macro, name, options, datastax_rails)
22
22
  klass = options[:through] ? ThroughReflection : AssociationReflection
23
23
  reflection = klass.new(macro, name, options, datastax_rails)
24
- self.reflections = self.reflections.merge(name => reflection)
24
+ self.reflections = reflections.merge(name => reflection)
25
25
  reflection
26
26
  end
27
27
 
@@ -55,7 +55,6 @@ module DatastaxRails
55
55
  end
56
56
  end
57
57
 
58
-
59
58
  # Abstract base class for AggregateReflection and AssociationReflection. Objects of
60
59
  # AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
61
60
  class MacroReflection
@@ -78,7 +77,7 @@ module DatastaxRails
78
77
  attr_reader :options
79
78
 
80
79
  attr_reader :datastax_rails
81
-
80
+
82
81
  # Returns a hash of all the denormalizations for this relationship (if any)
83
82
  attr_reader :denorms
84
83
 
@@ -110,12 +109,12 @@ module DatastaxRails
110
109
 
111
110
  # Returns +true+ if +self+ and +other_aggregation+ have the same +name+ attribute, +datastax_rails+ attribute,
112
111
  # and +other_aggregation+ has an options hash assigned to it.
113
- def ==(other_aggregation)
112
+ def ==(other)
114
113
  super ||
115
- other_aggregation.kind_of?(self.class) &&
116
- name == other_aggregation.name &&
117
- other_aggregation.options &&
118
- datastax_rails == other_aggregation.datastax_rails
114
+ other.is_a?(self.class) &&
115
+ name == other.name &&
116
+ other.options &&
117
+ datastax_rails == other.datastax_rails
119
118
  end
120
119
 
121
120
  # XXX: Do we need to sanitize our query?
@@ -124,14 +123,20 @@ module DatastaxRails
124
123
  end
125
124
 
126
125
  private
127
- def derive_class_name
128
- name.to_s.camelize
129
- end
126
+
127
+ def derive_class_name
128
+ name.to_s.camelize
129
+ end
130
130
  end
131
131
 
132
132
  # Holds all the meta-data about an association as it was specified in the
133
133
  # DatastaxRails class.
134
134
  class AssociationReflection < MacroReflection
135
+ # Returns whether or not this association reflection is for a collection
136
+ # association. Returns +true+ if the +macro+ is either +has_many+ or
137
+ # +has_and_belongs_to_many+, +false+ otherwise.
138
+ attr_reader :collection
139
+ alias_method :collection?, :collection
135
140
  # Returns the target association's class.
136
141
  #
137
142
  # class Author < DatastaxRails::Base
@@ -147,7 +152,7 @@ module DatastaxRails
147
152
  def klass
148
153
  @klass ||= datastax_rails.send(:compute_type, class_name)
149
154
  end
150
-
155
+
151
156
  def initialize(macro, name, options, datastax_rails)
152
157
  super
153
158
  @collection = macro.in?([:has_many, :has_and_belongs_to_many])
@@ -185,11 +190,11 @@ module DatastaxRails
185
190
 
186
191
  # klass option is necessary to support loading polymorphic associations
187
192
  # def association_primary_key(klass = nil)
188
- # options[:primary_key] || primary_key(klass || self.klass)
193
+ # options[:primary_key] || primary_key(klass || self.klass)
189
194
  # end
190
- #
195
+ #
191
196
  # def datastax_rails_primary_key
192
- # @datastax_rails_primary_key ||= options[:primary_key] || primary_key(solandra_object)
197
+ # @datastax_rails_primary_key ||= options[:primary_key] || primary_key(solandra_object)
193
198
  # end
194
199
 
195
200
  def check_validity!
@@ -197,10 +202,9 @@ module DatastaxRails
197
202
  end
198
203
 
199
204
  def check_validity_of_inverse!
200
- unless options[:polymorphic]
201
- if has_inverse? && inverse_of.nil?
202
- raise InverseOfAssociationNotFoundError.new(self)
203
- end
205
+ return if options[:polymorphic]
206
+ if inverse? && inverse_of.nil?
207
+ fail InverseOfAssociationNotFoundError.new(self)
204
208
  end
205
209
  end
206
210
 
@@ -225,25 +229,18 @@ module DatastaxRails
225
229
  [[options[:conditions]].compact]
226
230
  end
227
231
 
228
- alias :source_macro :macro
232
+ alias_method :source_macro, :macro
229
233
 
230
- def has_inverse?
234
+ def inverse?
231
235
  @options[:inverse_of]
232
236
  end
233
237
 
234
238
  def inverse_of
235
- if has_inverse?
239
+ if inverse?
236
240
  @inverse_of ||= klass.reflect_on_association(options[:inverse_of])
237
241
  end
238
242
  end
239
243
 
240
- # Returns whether or not this association reflection is for a collection
241
- # association. Returns +true+ if the +macro+ is either +has_many+ or
242
- # +has_and_belongs_to_many+, +false+ otherwise.
243
- def collection?
244
- @collection
245
- end
246
-
247
244
  # Returns whether or not the association should be validated as part of
248
245
  # the parent's validation.
249
246
  #
@@ -284,32 +281,33 @@ module DatastaxRails
284
281
  end
285
282
 
286
283
  private
287
- def derive_class_name
288
- class_name = name.to_s.camelize
289
- class_name = class_name.singularize if collection?
290
- class_name
291
- end
292
284
 
293
- def derive_foreign_key
294
- if belongs_to?
295
- "#{name}_id"
296
- elsif options[:as]
297
- "#{options[:as]}_id"
298
- else
299
- datastax_rails.name.foreign_key
300
- end
285
+ def derive_class_name
286
+ class_name = name.to_s.camelize
287
+ class_name = class_name.singularize if collection?
288
+ class_name
289
+ end
290
+
291
+ def derive_foreign_key
292
+ if belongs_to?
293
+ "#{name}_id"
294
+ elsif options[:as]
295
+ "#{options[:as]}_id"
296
+ else
297
+ datastax_rails.name.foreign_key
301
298
  end
299
+ end
302
300
 
303
- # def primary_key(klass)
304
- # klass.key || raise(UnknownPrimaryKey.new(klass))
305
- # end
301
+ # def primary_key(klass)
302
+ # klass.key || raise(UnknownPrimaryKey.new(klass))
303
+ # end
306
304
  end
307
-
305
+
308
306
  # Holds all the meta-data about a :through association as it was specified
309
307
  # in the DatastaxRails class.
310
308
  class ThroughReflection < AssociationReflection #:nodoc:
311
309
  delegate :foreign_key, :foreign_type, :association_foreign_key,
312
- :datastax_rails_primary_key, :type, :to => :source_reflection
310
+ :datastax_rails_primary_key, :type, to: :source_reflection
313
311
 
314
312
  # Gets the source of the through reflection. It checks both a singularized
315
313
  # and pluralized form for <tt>:belongs_to</tt> or <tt>:has_many</tt>.
@@ -320,7 +318,9 @@ module DatastaxRails
320
318
  # end
321
319
  #
322
320
  def source_reflection
323
- @source_reflection ||= source_reflection_names.collect { |name| through_reflection.klass.reflect_on_association(name) }.compact.first
321
+ @source_reflection ||= source_reflection_names.map do |name|
322
+ through_reflection.klass.reflect_on_association(name)
323
+ end.compact.first
324
324
  end
325
325
 
326
326
  # Returns the AssociationReflection object specified in the <tt>:through</tt> option
@@ -423,7 +423,8 @@ module DatastaxRails
423
423
  # [:singularized, :pluralized]
424
424
  #
425
425
  def source_reflection_names
426
- @source_reflection_names ||= (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).collect { |n| n.to_sym }
426
+ @source_reflection_names ||=
427
+ (options[:source] ? [options[:source]] : [name.to_s.singularize, name]).map { |n| n.to_sym }
427
428
  end
428
429
 
429
430
  def source_options
@@ -436,37 +437,38 @@ module DatastaxRails
436
437
 
437
438
  def check_validity!
438
439
  if through_reflection.nil?
439
- raise HasManyThroughAssociationNotFoundError.new(datastax_rails.name, self)
440
+ fail HasManyThroughAssociationNotFoundError.new(datastax_rails.name, self)
440
441
  end
441
442
 
442
443
  if through_reflection.options[:polymorphic]
443
- raise HasManyThroughAssociationPolymorphicThroughError.new(datastax_rails.name, self)
444
+ fail HasManyThroughAssociationPolymorphicThroughError.new(datastax_rails.name, self)
444
445
  end
445
446
 
446
447
  if source_reflection.nil?
447
- raise HasManyThroughSourceAssociationNotFoundError.new(self)
448
+ fail HasManyThroughSourceAssociationNotFoundError.new(self)
448
449
  end
449
450
 
450
451
  if options[:source_type] && source_reflection.options[:polymorphic].nil?
451
- raise HasManyThroughAssociationPointlessSourceTypeError.new(datastax_rails.name, self, source_reflection)
452
+ fail HasManyThroughAssociationPointlessSourceTypeError.new(datastax_rails.name, self, source_reflection)
452
453
  end
453
454
 
454
455
  if source_reflection.options[:polymorphic] && options[:source_type].nil?
455
- raise HasManyThroughAssociationPolymorphicSourceError.new(datastax_rails.name, self, source_reflection)
456
+ fail HasManyThroughAssociationPolymorphicSourceError.new(datastax_rails.name, self, source_reflection)
456
457
  end
457
458
 
458
459
  if macro == :has_one && through_reflection.collection?
459
- raise HasOneThroughCantAssociateThroughCollection.new(datastax_rails.name, self, through_reflection)
460
+ fail HasOneThroughCantAssociateThroughCollection.new(datastax_rails.name, self, through_reflection)
460
461
  end
461
462
 
462
463
  check_validity_of_inverse!
463
464
  end
464
465
 
465
466
  private
466
- def derive_class_name
467
- # get the class_name of the belongs_to association of the through reflection
468
- options[:source_type] || source_reflection.class_name
469
- end
467
+
468
+ def derive_class_name
469
+ # get the class_name of the belongs_to association of the through reflection
470
+ options[:source_type] || source_reflection.class_name
471
+ end
470
472
  end
471
473
  end
472
474
  end
@@ -25,12 +25,12 @@ module DatastaxRails
25
25
  records.each { |record| yield record }
26
26
  end
27
27
  end
28
-
28
+
29
29
  # Same as {find_each} but yields the index as a second parameter.
30
30
  def find_each_with_index(options = {})
31
31
  idx = 0
32
32
  find_in_batches(options) do |records|
33
- records.each do |record|
33
+ records.each do |record|
34
34
  yield record, idx
35
35
  idx += 1
36
36
  end
@@ -50,7 +50,7 @@ module DatastaxRails
50
50
  #
51
51
  # It's not possible to set the order. For Cassandra based batching, the
52
52
  # order is set according to Cassandra's key placement strategy. For Solr
53
- # based batching, the order is ascending order of the primary key.
53
+ # based batching, the order is ascending order of the primary key.
54
54
  # You can't set the limit either. That's used to control the batch sizes.
55
55
  #
56
56
  # Example:
@@ -65,20 +65,21 @@ module DatastaxRails
65
65
  def find_in_batches(options = {})
66
66
  relation = self
67
67
 
68
- unless (@order_values.empty?)
69
- DatastaxRails::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
68
+ unless @order_values.empty?
69
+ DatastaxRails::Base.logger.warn('Scoped order and limit are ignored, ' \
70
+ "it's forced to be batch order and batch size")
70
71
  end
71
72
 
72
73
  if (finder_options = options.except(:start, :batch_size)).present?
73
- raise "You can't specify an order, it's forced to be #{@klass.primary_key}" if options[:order].present?
74
- raise "You can't specify a limit, it's forced to be the batch_size" if options[:limit].present?
74
+ fail "You can't specify an order, it's forced to be #{@klass.primary_key}" if options[:order].present?
75
+ fail "You can't specify a limit, it's forced to be the batch_size" if options[:limit].present?
75
76
 
76
77
  relation = apply_finder_options(finder_options)
77
78
  end
78
79
 
79
80
  start = options.delete(:start)
80
81
  batch_size = options.delete(:batch_size) || 1000
81
-
82
+
82
83
  relation = relation.limit(batch_size)
83
84
  relation = relation.order(@klass.primary_key) if relation.use_solr_value
84
85
  records = start ? relation.where(@klass.primary_key).greater_than(start).to_a : relation.to_a
@@ -89,14 +90,12 @@ module DatastaxRails
89
90
 
90
91
  break if records_size < batch_size
91
92
  if offset
92
- if relation.use_solr_value
93
- offset = ::Cql::Uuid.new(offset.value+1)
94
- end
93
+ offset = ::Cql::Uuid.new(offset.value + 1) if relation.use_solr_value
95
94
  records = relation.where(@klass.primary_key).greater_than(offset).to_a
96
95
  else
97
- raise "Batch order not included in the custom select clause"
96
+ fail 'Batch order not included in the custom select clause'
98
97
  end
99
98
  end
100
99
  end
101
100
  end
102
- end
101
+ end
@@ -3,24 +3,27 @@ module DatastaxRails
3
3
  # Instructs SOLR to get facet counts on the passed in field. Results are available in the facets accessor.
4
4
  # Facets include Field and Range (Date is not supported as it is depricated in Solr - use a range instead).
5
5
  #
6
- # results = Article.field_facet(:author)
7
- # results.facets => {"author"=>["vonnegut", 2. "asimov", 3]}
6
+ # results = Article.field_facet(:author)
7
+ # results.facets => {"author"=>["vonnegut", 2. "asimov", 3]}
8
8
  #
9
- # Model.field_facet(:author)
10
- # Model.field_facet(:author, :sort => 'count', :limit => 10, :mincount => 1)
11
- # Model.range_facet(:price, 500, 1000, 10)
12
- # Model.range_facet(:price, 500, 1000, 10, :include => 'all')
13
- # Model.range_facet(:publication_date, "1968-01-01T00:00:00Z", "2000-01-01T00:00:00Z", "+1YEAR")
9
+ # Model.field_facet(:author)
10
+ # Model.field_facet(:author, :sort => 'count', :limit => 10, :mincount => 1)
11
+ # Model.range_facet(:price, 500, 1000, 10)
12
+ # Model.range_facet(:price, 500, 1000, 10, :include => 'all')
13
+ # Model.range_facet(:publication_date, "1968-01-01T00:00:00Z", "2000-01-01T00:00:00Z", "+1YEAR")
14
14
  #
15
15
  # Range Gap syntax for dates: +1YEAR, +5YEAR, +5YEARS, +1MONTH, +1DAY
16
16
  #
17
17
  # Useful constants:
18
18
  #
19
- # DatastaxRails::FacetMethods::BY_YEAR (+1YEAR)
20
- # DatastaxRails::FacetMethods::BY_MONTH (+1MONTH)
21
- # DatastaxRails::FacetMethods::BY_DAY (+1DAY)
19
+ # DatastaxRails::FacetMethods::BY_YEAR (+1YEAR)
20
+ # DatastaxRails::FacetMethods::BY_MONTH (+1MONTH)
21
+ # DatastaxRails::FacetMethods::BY_DAY (+1DAY)
22
22
  #
23
- # Model.range_facet(:publication_date, "1968-01-01T00:00:00Z", "2000-01-01T00:00:00Z", DatastaxRails::FacetMethods::BY_YEAR)
23
+ # Model.range_facet(:publication_date,
24
+ # "1968-01-01T00:00:00Z",
25
+ # "2000-01-01T00:00:00Z",
26
+ # DatastaxRails::FacetMethods::BY_YEAR)
24
27
  #
25
28
  # These method can be called multiple times to facet on different fields
26
29
  #
@@ -29,40 +32,48 @@ module DatastaxRails
29
32
  # @return [DatastaxRails::Relation] a new Relation object
30
33
  #
31
34
  # Field Facet Option Values:
32
- # prefix: [String] Facet prefix
33
- # limit: [Number] Facet result limit (Solr defaults to 100)
34
- # sort: [String: count | index] Sort Order (Solr defaults to index, unless a limit is specified, then defaults to index)
35
- # offset: [Number] Facet result offset (Solr defaults to 0)
36
- # mincount [Number] Facet minimum number of occurances before including in the result set (Solr defaults to 0)
35
+ # * prefix: [String] Facet prefix
36
+ # * limit: [Number] Facet result limit (Solr defaults to 100)
37
+ # * sort: [String: count | index] Sort Order (Solr defaults to index, unless a limit is specified,
38
+ # then defaults to index)
39
+ # * offset: [Number] Facet result offset (Solr defaults to 0)
40
+ # * mincount [Number] Facet minimum number of occurances before including in the result set (Solr defaults to 0)
41
+ #
37
42
  # Note: You can pass any valid facet option value, and it will be passed to Solr
38
- #
43
+ #
39
44
  # Range Facet Option Values:
40
- # start [String] Range start
41
- # end: [String] Range end value
42
- # gap: [String] Range gap (see examples above)
43
- # include [String: lower | upper | edge | outer | all] (Solr defaults to lower) include / exclude upper and lower range values
44
- # other [String: before | after | between | none | all] include / exclude counts
45
+ # * start [String] Range start
46
+ # * end: [String] Range end value
47
+ # * gap: [String] Range gap (see examples above)
48
+ # * include: [String: lower | upper | edge | outer | all] (Solr defaults to lower)
49
+ # include / exclude upper and lower range values
50
+ # * other: [String: before | after | between | none | all] include / exclude counts
51
+ #
45
52
  # Note: You can pass any valid facet option value, and it will be passed to Solr
46
- #
53
+ #
47
54
  # Date Facet? - use Range Facet! They were depricated in Solr 3
48
-
49
- BY_YEAR = "+1YEAR"
50
- BY_MONTH = "+1MONTH"
51
- BY_DAY = "+1DAY"
52
-
55
+
56
+ BY_YEAR = '+1YEAR'
57
+ BY_MONTH = '+1MONTH'
58
+ BY_DAY = '+1DAY'
59
+
53
60
  def field_facet(field, options = {})
54
61
  return self if field.blank?
55
62
  clone.tap do |r|
56
- r.field_facet_values << {:field => field.to_s, :options => options}
63
+ r.field_facet_values << { field: field.to_s, options: options }
57
64
  end
58
65
  end
59
-
66
+
60
67
  def range_facet(field, start_range, end_range, gap, options = {})
61
68
  return self if field.blank?
62
69
  clone.tap do |r|
63
- r.range_facet_values << {:field => field.to_s, :options => options.merge(:start => start_range.to_s, :end => end_range.to_s, :gap => gap.to_s)}
70
+ r.range_facet_values << { field: field.to_s,
71
+ options: options.merge(start: start_range.to_s,
72
+ end: end_range.to_s,
73
+ gap: gap.to_s
74
+ )
75
+ }
64
76
  end
65
77
  end
66
-
67
78
  end
68
- end
79
+ end