datastax_rails 2.0.12 → 2.0.15

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -34,32 +34,32 @@ module DatastaxRails
34
34
  # is computed directly through Solr and does not trigger by itself the
35
35
  # instantiation of the actual post records.
36
36
  class CollectionProxy #:nodoc:
37
- alias :proxy_extend :extend
38
-
39
- instance_methods.each { |m| undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/ }
40
-
41
- delegate :order, :limit, :where, :to => :scoped
42
- delegate :target, :load_target, :loaded?, :scoped, :to => :@association
37
+ attr_reader :association
38
+ alias_method :proxy_association, :association
39
+ alias_method :proxy_extend, :extend
40
+
41
+ instance_methods.each do |m|
42
+ undef_method m unless m.to_s =~ /^(?:nil\?|send|object_id|to_a)$|^__|^respond_to|proxy_/
43
+ end
44
+
45
+ delegate :order, :limit, :where, to: :scoped
46
+ delegate :target, :load_target, :loaded?, :scoped, to: :@association
43
47
  delegate :select, :find, :first, :last, :build, :create, :create!, :destroy_all, :destroy,
44
- :delete, :delete_all, :count, :size, :length, :empty?, :any?, :many?, :to => :@association
45
-
48
+ :delete, :delete_all, :count, :size, :length, :empty?, :any?, :many?, to: :@association
49
+
46
50
  def initialize(association)
47
51
  @association = association
48
52
  Array.wrap(association.options[:extend]).each { |ext| proxy_extend(ext) }
49
53
  end
50
-
54
+
51
55
  alias_method :new, :build
52
-
53
- def proxy_association
54
- @association
55
- end
56
-
56
+
57
57
  def respond_to?(name, include_private = false)
58
58
  super ||
59
59
  (load_target && target.respond_to?(name, include_private)) ||
60
60
  proxy_association.klass.respond_to?(name, include_private)
61
61
  end
62
-
62
+
63
63
  def method_missing(method, *args, &block)
64
64
  if target.respond_to?(method) || (!proxy_association.klass.respond_to?(method) && Class.respond_to?(method))
65
65
  if load_target
@@ -78,28 +78,28 @@ module DatastaxRails
78
78
  scoped.send(method, *args, &block)
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Forwards <tt>===</tt> explicitly to the \target because the instance method
83
83
  # removal above doesn't catch it. Loads the \target if needed.
84
84
  def ===(other)
85
- other === load_target
85
+ other === load_target # rubocop:disable Style/CaseEquality
86
86
  end
87
-
87
+
88
88
  def to_ary
89
89
  load_target.dup
90
90
  end
91
91
  alias_method :to_a, :to_ary
92
-
92
+
93
93
  def <<(*records)
94
94
  proxy_association.concat(records) && self
95
95
  end
96
96
  alias_method :push, :<<
97
-
97
+
98
98
  def clear
99
99
  destroy_all
100
100
  self
101
101
  end
102
-
102
+
103
103
  def reload
104
104
  proxy_association.reload
105
105
  self
@@ -3,42 +3,42 @@ module DatastaxRails
3
3
  module Associations
4
4
  class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc:
5
5
  attr_reader :join_name
6
-
6
+
7
7
  def initialize(owner, reflection)
8
- join_name = [owner.class.name.underscore, reflection.class_name.underscore].sort.join('_')
8
+ self.join_name = [owner.class.name.underscore, reflection.class_name.underscore].sort.join('_')
9
9
  super
10
10
  end
11
-
11
+
12
12
  def insert_record(record, validate = true, raise = false)
13
13
  if record.new_record?
14
14
  if raise
15
- record.save!(:validate => validate)
15
+ record.save!(validate: validate)
16
16
  else
17
- return unless record.save(:validate => validate)
17
+ return unless record.save(validate: validate)
18
18
  end
19
19
  end
20
-
21
- left, right = [[record.class.name, record.id], [owner.class.name, owner.id]].sort {|a,b|b.first <=> a.first}
22
-
23
- DatastaxRails::Base.connection.insert(join_column_family,
24
- SimpleUUID::UUID.new.to_guid,
25
- {:left => "#{join_name}:#{left.last}",
26
- :right => "#{join_name}:#{right.last}"})
20
+
21
+ left, right = [[record.class.name, record.id], [owner.class.name, owner.id]].sort { |a, b|b.first <=> a.first }
22
+
23
+ DatastaxRails::Base.connection.insert(join_column_family,
24
+ SimpleUUID::UUID.new.to_guid,
25
+ left: "#{join_name}:#{left.last}",
26
+ right: "#{join_name}:#{right.last}")
27
27
  end
28
-
29
-
28
+
30
29
  private
31
- def join_column_family
32
- "many_to_many_joins"
33
- end
34
-
35
- def count_records
36
- load_target.size
37
- end
38
-
39
- def invertible_for?(record)
40
- false
41
- end
30
+
31
+ def join_column_family
32
+ 'many_to_many_joins'
33
+ end
34
+
35
+ def count_records
36
+ load_target.size
37
+ end
38
+
39
+ def invertible_for?(_record)
40
+ false
41
+ end
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -10,50 +10,50 @@ module DatastaxRails
10
10
  set_inverse_instance(record)
11
11
 
12
12
  if raise
13
- record.save!(:validate => validate)
13
+ record.save!(validate: validate)
14
14
  else
15
- record.save(:validate => validate)
15
+ record.save(validate: validate)
16
16
  end
17
17
  end
18
-
18
+
19
19
  private
20
-
21
- # Returns the number of records in this collection.
22
- #
23
- # This does not depend on whether the collection has already been loaded
24
- # or not. The +size+ method is the one that takes the loaded flag into
25
- # account and delegates to +count_records+ if needed.
26
- #
27
- # If the collection is empty the target is set to an empty array and
28
- # the loaded flag is set to true as well.
29
- def count_records
30
- count = scoped.count
31
-
32
- # If there's nothing in the database and @target has no new records
33
- # we are certain the current target is an empty array. This is a
34
- # documented side-effect of the method that may avoid an extra SELECT.
35
- @target ||= [] and loaded! if count == 0
36
-
37
- count
38
- end
39
-
40
- # Deletes the records according to the <tt>:dependent</tt> option.
41
- def delete_records(records, method)
42
- if method == :destroy
43
- records.each { |r| r.destroy }
20
+
21
+ # Returns the number of records in this collection.
22
+ #
23
+ # This does not depend on whether the collection has already been loaded
24
+ # or not. The +size+ method is the one that takes the loaded flag into
25
+ # account and delegates to +count_records+ if needed.
26
+ #
27
+ # If the collection is empty the target is set to an empty array and
28
+ # the loaded flag is set to true as well.
29
+ def count_records
30
+ count = scoped.count
31
+
32
+ # If there's nothing in the database and @target has no new records
33
+ # we are certain the current target is an empty array. This is a
34
+ # documented side-effect of the method that may avoid an extra SELECT.
35
+ @target ||= [] && loaded! if count == 0
36
+
37
+ count
38
+ end
39
+
40
+ # Deletes the records according to the <tt>:dependent</tt> option.
41
+ def delete_records(records, method)
42
+ if method == :destroy
43
+ records.each { |r| r.destroy }
44
+ else
45
+ keys = records.map { |r| r[reflection.association_primary_key] }
46
+ scope = scoped.where(reflection.association_primary_key => keys)
47
+
48
+ if method == :delete_all
49
+ scope.delete_all
44
50
  else
45
- keys = records.map { |r| r[reflection.association_primary_key] }
46
- scope = scoped.where(reflection.association_primary_key => keys)
47
-
48
- if method == :delete_all
49
- scope.delete_all
50
- else
51
- # This is for :nullify which isn't actually supported yet,
52
- # but this should work once it is
53
- scope.update_all(reflection.foreign_key => nil)
54
- end
51
+ # This is for :nullify which isn't actually supported yet,
52
+ # but this should work once it is
53
+ scope.update_all(reflection.foreign_key => nil)
55
54
  end
56
55
  end
56
+ end
57
57
  end
58
58
  end
59
- end
59
+ end
@@ -16,53 +16,52 @@ module DatastaxRails
16
16
  if owner.persisted? && save && !record.save
17
17
  nullify_owner_attributes(record)
18
18
  set_owner_attributes(target) if target
19
- raise RecordNotSaved, "Failed to save the new associated #{reflection.name}."
19
+ fail RecordNotSaved, "Failed to save the new associated #{reflection.name}."
20
20
  end
21
21
  end
22
22
 
23
23
  self.target = record
24
24
  end
25
-
25
+
26
26
  def delete(method = options[:dependent])
27
- if load_target
28
- case method
29
- when :delete
30
- target.delete
31
- when :destroy
32
- target.destroy
33
- when :nullify
34
- target.update_attribute(reflection.foreign_key, nil)
35
- end
27
+ return unless load_target
28
+ case method
29
+ when :delete
30
+ target.delete
31
+ when :destroy
32
+ target.destroy
33
+ when :nullify
34
+ target.update_attribute(reflection.foreign_key, nil)
36
35
  end
37
36
  end
38
37
 
39
38
  private
40
39
 
41
- # The reason that the save param for replace is false, if for create (not just build),
42
- # is because the setting of the foreign keys is actually handled by the scoping when
43
- # the record is instantiated, and so they are set straight away and do not need to be
44
- # updated within replace.
45
- def set_new_record(record)
46
- replace(record, false)
47
- end
40
+ # The reason that the save param for replace is false, if for create (not just build),
41
+ # is because the setting of the foreign keys is actually handled by the scoping when
42
+ # the record is instantiated, and so they are set straight away and do not need to be
43
+ # updated within replace.
44
+ def set_new_record(record) # rubocop:disable Style/AccessorMethodName
45
+ replace(record, false)
46
+ end
48
47
 
49
- def remove_target!(method)
50
- if method.in?([:delete, :destroy])
51
- target.send(method)
52
- else
53
- nullify_owner_attributes(target)
48
+ def remove_target!(method)
49
+ if method.in?([:delete, :destroy])
50
+ target.send(method)
51
+ else
52
+ nullify_owner_attributes(target)
54
53
 
55
- if target.persisted? && owner.persisted? && !target.save
56
- set_owner_attributes(target)
57
- raise RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " +
58
- "The record failed to save when after its foreign key was set to nil."
59
- end
54
+ if target.persisted? && owner.persisted? && !target.save
55
+ set_owner_attributes(target)
56
+ fail RecordNotSaved, "Failed to remove the existing associated #{reflection.name}. " \
57
+ 'The record failed to save when after its foreign key was set to nil.'
60
58
  end
61
59
  end
60
+ end
62
61
 
63
- def nullify_owner_attributes(record)
64
- record[reflection.foreign_key] = nil
65
- end
62
+ def nullify_owner_attributes(record)
63
+ record[reflection.foreign_key] = nil
64
+ end
66
65
  end
67
66
  end
68
- end
67
+ end
@@ -6,16 +6,16 @@ module DatastaxRails
6
6
  reload if force_reload || !loaded? || stale_target?
7
7
  target
8
8
  end
9
-
9
+
10
10
  # Implements the writer method, e.g. foo.items= for Foo.has_many :items
11
11
  def writer(record)
12
12
  replace(record)
13
13
  end
14
-
14
+
15
15
  def create(attributes = {}, options = {}, &block)
16
16
  create_record(attributes, options, &block)
17
17
  end
18
-
18
+
19
19
  def create!(attributes = {}, options = {}, &block)
20
20
  create_record(attributes, options, true, &block)
21
21
  end
@@ -26,33 +26,34 @@ module DatastaxRails
26
26
  set_new_record(record)
27
27
  record
28
28
  end
29
-
29
+
30
30
  private
31
- def create_scope
32
- scoped.scope_for_create.stringify_keys.except("id")
33
- end
34
-
35
- def find_target
36
- scoped.first.tap { |record| set_inverse_instance(record) }
37
- end
38
-
39
- # Implemented by subclasses
40
- def replace(record)
41
- raise NotImplementedError, "Subclasses must implement a replace(record) method"
42
- end
43
-
44
- def set_new_record(record)
45
- replace(record)
46
- end
47
-
48
- def create_record(attributes, options, raise_error = false)
49
- record = build_record(attributes, options)
50
- yield(record) if block_given?
51
- saved = record.save
52
- set_new_record(record)
53
- raise RecordInvalid.new(record) if !saved && raise_error
54
- record
55
- end
31
+
32
+ def create_scope
33
+ scoped.scope_for_create.stringify_keys.except('id')
34
+ end
35
+
36
+ def find_target
37
+ scoped.first.tap { |record| set_inverse_instance(record) }
38
+ end
39
+
40
+ # Implemented by subclasses
41
+ def replace(_record)
42
+ fail NotImplementedError, 'Subclasses must implement a replace(record) method'
43
+ end
44
+
45
+ def set_new_record(record) # rubocop:disable Style/AccessorMethodName
46
+ replace(record)
47
+ end
48
+
49
+ def create_record(attributes, options, raise_error = false)
50
+ record = build_record(attributes, options)
51
+ yield(record) if block_given?
52
+ saved = record.save
53
+ set_new_record(record)
54
+ fail RecordInvalid.new(record) if !saved && raise_error
55
+ record
56
+ end
56
57
  end
57
58
  end
58
- end
59
+ end
@@ -1,8 +1,10 @@
1
+ # rubocop:disable Style/PredicateName
1
2
  module DatastaxRails
3
+ # Associations holds all the functionality related to DSR associations
2
4
  module Associations
3
5
  extend ActiveSupport::Concern
4
6
  extend ActiveSupport::Autoload
5
-
7
+
6
8
  autoload :Association
7
9
  autoload :AssociationScope
8
10
  autoload :SingularAssociation
@@ -11,19 +13,20 @@ module DatastaxRails
11
13
  autoload :BelongsToAssociation
12
14
  autoload :HasOneAssociation
13
15
  autoload :HasManyAssociation
14
-
16
+
17
+ # Builder holds all the classes related to building the association
15
18
  module Builder
16
19
  extend ActiveSupport::Autoload
17
-
20
+
18
21
  autoload :Association
19
22
  autoload :SingularAssociation
20
23
  autoload :CollectionAssociation
21
-
24
+
22
25
  autoload :BelongsTo
23
26
  autoload :HasOne
24
27
  autoload :HasMany
25
28
  end
26
-
29
+
27
30
  # Clears out the association cache.
28
31
  def clear_association_cache #:nodoc:
29
32
  @association_cache.clear if persisted?
@@ -44,25 +47,26 @@ module DatastaxRails
44
47
 
45
48
  association
46
49
  end
47
-
50
+
48
51
  private
49
- # Returns the specified association instance if it responds to :loaded?, nil otherwise.
50
- def association_instance_get(name)
51
- @association_cache ||= {}
52
- @association_cache[name.to_sym]
53
- end
54
52
 
55
- # Set the specified association instance.
56
- def association_instance_set(name, association)
57
- @association_cache ||= {}
58
- @association_cache[name] = association
59
- end
60
-
53
+ # Returns the specified association instance if it responds to :loaded?, nil otherwise.
54
+ def association_instance_get(name)
55
+ @association_cache ||= {}
56
+ @association_cache[name.to_sym]
57
+ end
58
+
59
+ # Set the specified association instance.
60
+ def association_instance_set(name, association)
61
+ @association_cache ||= {}
62
+ @association_cache[name] = association
63
+ end
64
+
61
65
  module ClassMethods
62
66
  def belongs_to(name, options = {})
63
67
  Builder::BelongsTo.build(self, name, options)
64
68
  end
65
-
69
+
66
70
  def has_many(name, options = {})
67
71
  Builder::HasMany.build(self, name, options)
68
72
  # klass = options[:class_name]
@@ -70,17 +74,16 @@ module DatastaxRails
70
74
  # foreign_key = options[:foreign_key]
71
75
  # foreign_key ||= self.name.foreign_key
72
76
  # define_method name do
73
- # klass.where(foreign_key)
77
+ # klass.where(foreign_key)
74
78
  # end
75
79
  end
76
-
77
- def has_and_belongs_to_many(name, options = {})
78
-
80
+
81
+ def has_and_belongs_to_many(_name, _options = {})
79
82
  end
80
-
83
+
81
84
  def has_one(name, options = {})
82
85
  Builder::HasOne.build(self, name, options)
83
86
  end
84
87
  end
85
88
  end
86
- end
89
+ end