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
@@ -1,56 +1,57 @@
1
- module DatastaxRails::Associations::Builder
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class Association #:nodoc:
3
3
  class_attribute :valid_options
4
4
  self.valid_options = [:class_name, :foreign_key]
5
-
5
+
6
6
  # Set by subclasses
7
7
  class_attribute :macro
8
-
8
+
9
9
  attr_reader :model, :name, :options, :reflection
10
-
10
+
11
11
  def self.build(model, name, options)
12
12
  new(model, name, options).build
13
13
  end
14
-
14
+
15
15
  def initialize(model, name, options)
16
16
  @model, @name, @options = model, name, options
17
17
  end
18
-
18
+
19
19
  def build
20
20
  validate_options
21
21
  reflection = model.create_reflection(self.class.macro, name, options, model)
22
22
  define_accessors
23
23
  reflection
24
24
  end
25
-
25
+
26
26
  def mixin
27
27
  @model.generated_attribute_methods
28
28
  end
29
-
29
+
30
30
  private
31
- def validate_options
32
- options.assert_valid_keys(self.class.valid_options)
33
- end
34
-
35
- def define_accessors
36
- define_readers
37
- define_writers
38
- end
39
-
40
- def define_readers
41
- name = self.name
42
-
43
- model.redefine_method(name) do |*params|
44
- association(name).reader(*params)
45
- end
31
+
32
+ def validate_options
33
+ options.assert_valid_keys(self.class.valid_options)
34
+ end
35
+
36
+ def define_accessors
37
+ define_readers
38
+ define_writers
39
+ end
40
+
41
+ def define_readers
42
+ name = self.name
43
+
44
+ model.redefine_method(name) do |*params|
45
+ association(name).reader(*params)
46
46
  end
47
-
48
- def define_writers
49
- name = self.name
50
-
51
- model.redefine_method("#{name}=") do |value|
52
- association(name).writer(value)
53
- end
47
+ end
48
+
49
+ def define_writers
50
+ name = self.name
51
+
52
+ model.redefine_method("#{name}=") do |value|
53
+ association(name).writer(value)
54
54
  end
55
+ end
55
56
  end
56
- end
57
+ end
@@ -1,30 +1,29 @@
1
- module DatastaxRails::Associations::Builder
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class BelongsTo < SingularAssociation
3
3
  self.macro = :belongs_to
4
-
4
+
5
5
  def build
6
6
  reflection = super
7
7
  configure_dependency
8
8
  reflection
9
9
  end
10
-
10
+
11
11
  private
12
-
13
- def configure_dependency
14
- if options[:dependent]
15
- unless options[:dependent].in?([:destroy, :delete])
16
- raise ArgumentError, "The :dependent option expects either :destroy or :delete (#{options[:dependent].inspect})"
17
- end
18
-
19
- method_name = "belongs_to_dependent_#{options[:dependent]}_for_#{name}"
20
- model.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
21
- def #{method_name}
22
- association = #{name}
23
- association.#{options[:dependent]} if association
24
- end
25
- eoruby
26
- model.after_destroy method_name
27
- end
12
+
13
+ def configure_dependency
14
+ return unless options[:dependent]
15
+ unless options[:dependent].in?([:destroy, :delete])
16
+ fail ArgumentError, "The :dependent option expects either :destroy or :delete (#{options[:dependent].inspect})"
28
17
  end
18
+
19
+ method_name = "belongs_to_dependent_#{options[:dependent]}_for_#{name}"
20
+ model.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
21
+ def #{method_name}
22
+ association = #{name}
23
+ association.#{options[:dependent]} if association
24
+ end
25
+ eoruby
26
+ model.after_destroy method_name
27
+ end
29
28
  end
30
- end
29
+ end
@@ -1,48 +1,48 @@
1
- module DatastaxRails::Associations::Builder #:nodoc:
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class CollectionAssociation < Association #:nodoc:
3
3
  CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
4
-
4
+
5
5
  self.valid_options += [:columm_family, :order, :uniq, :before_add, :before_remove, :after_add, :after_remove]
6
-
6
+
7
7
  def self.build(model, name, options)
8
8
  new(model, name, options).build
9
9
  end
10
-
10
+
11
11
  def build
12
- reflection = super
12
+ @reflection = super
13
13
  CALLBACKS.each { |callback_name| define_callback(callback_name) }
14
14
  end
15
-
15
+
16
16
  def writable?
17
17
  true
18
18
  end
19
-
19
+
20
20
  protected
21
-
22
- def define_callback(callback_name)
23
- full_callback_name = "#{callback_name}_for_#{name}"
24
-
25
- # XXX : why do i need method_defined? I think its because of the inheritance chain
26
- model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
27
- model.send("#{full_callback_name}=", Array.wrap(options[callback_name.to_sym]))
28
- end
29
-
30
- def define_readers
31
- super
32
-
33
- name = self.name
34
- mixin.redefine_method("#{name.to_s.singularize}_ids") do
35
- association(name).ids_reader
36
- end
21
+
22
+ def define_callback(callback_name)
23
+ full_callback_name = "#{callback_name}_for_#{name}"
24
+
25
+ # XXX : why do i need method_defined? I think its because of the inheritance chain
26
+ model.class_attribute full_callback_name.to_sym unless model.method_defined?(full_callback_name)
27
+ model.send("#{full_callback_name}=", Array.wrap(options[callback_name.to_sym]))
28
+ end
29
+
30
+ def define_readers
31
+ super
32
+
33
+ name = self.name
34
+ mixin.redefine_method("#{name.to_s.singularize}_ids") do
35
+ association(name).ids_reader
37
36
  end
38
-
39
- def define_writers
40
- super
41
-
42
- name = self.name
43
- mixin.redefine_method("#{name.to_s.singularize}_ids=") do |ids|
44
- association(name).ids_writer(ids)
45
- end
37
+ end
38
+
39
+ def define_writers
40
+ super
41
+
42
+ name = self.name
43
+ mixin.redefine_method("#{name.to_s.singularize}_ids=") do |ids|
44
+ association(name).ids_writer(ids)
46
45
  end
46
+ end
47
47
  end
48
- end
48
+ end
@@ -1,36 +1,36 @@
1
- module DatastaxRails::Associations::Builder #:nodoc:
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class HasAndBelongsToMany < CollectionAssociation #:nodoc:
3
3
  self.macro = :has_and_belongs_to_many
4
-
4
+
5
5
  def build
6
6
  reflection = super
7
7
  define_destroy_hook
8
8
  check_for_join_column_family
9
9
  reflection
10
10
  end
11
-
11
+
12
12
  private
13
- def define_destroy_hook
14
- name = self.name
15
- model.send(:include, Module.new {
16
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
+
14
+ def define_destroy_hook
15
+ name = self.name
16
+ model.send(:include, Module.new do
17
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
17
18
  def destroy_associations
18
19
  association(#{name.to_sym.inspect}).delete_all_on_destroy
19
20
  super
20
21
  end
21
22
  RUBY
22
- })
23
- end
24
-
25
- def check_for_join_column_family
26
- unless DatastaxRails::Base.connection.column_families.has_key?("many_to_many_joins")
27
- cf = Cassandra::ColumnFamily.new
28
- cf.name = "many_to_many_joins"
29
- cf.keyspace = DatastaxRails::Base.connection.keyspace
30
- cf.comparator_type = 'BytesType'
31
- cf.column_type = 'Standard'
32
- DatastaxRails::Base.connection.add_column_family(cf)
33
- end
34
- end
23
+ end)
24
+ end
25
+
26
+ def check_for_join_column_family
27
+ return if DatastaxRails::Base.connection.column_families.key?('many_to_many_joins')
28
+ cf = Cassandra::ColumnFamily.new
29
+ cf.name = 'many_to_many_joins'
30
+ cf.keyspace = DatastaxRails::Base.connection.keyspace
31
+ cf.comparator_type = 'BytesType'
32
+ cf.column_type = 'Standard'
33
+ DatastaxRails::Base.connection.add_column_family(cf)
34
+ end
35
35
  end
36
- end
36
+ end
@@ -1,54 +1,53 @@
1
- module DatastaxRails::Associations::Builder
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class HasMany < CollectionAssociation #:nodoc:
3
3
  self.macro = :has_many
4
-
4
+
5
5
  self.valid_options += [:primary_key, :dependent, :source_type]
6
-
6
+
7
7
  def build
8
8
  reflection = super
9
9
  configure_dependency
10
10
  reflection
11
11
  end
12
-
12
+
13
13
  private
14
-
15
- def configure_dependency
16
- if options[:dependent]
17
- unless options[:dependent].in?([:destroy]) # Only destroy and restrict supported for now
18
- raise ArgumentError, "The :dependent option only handles :destroy or :restrict for now (#{options[:dependent].inspect})"
19
- end
20
-
21
- send("define_#{options[:dependent]}_dependency_method")
22
- model.before_destroy dependency_method_name
23
- end
24
- end
25
-
26
- def define_destroy_dependency_method
27
- name = self.name
28
- mixin.redefine_method(dependency_method_name) do
29
- send(name).each do |o|
30
- # No point in executing the counter update since we're going to destroy the parent anyway
31
- counter_method = ('belongs_to_counter_cache_before_destroy_for_' + self.class.name.downcase).to_sym
32
- if o.respond_to?(counter_method)
33
- class << o
34
- self
35
- end.send(:define_method, counter_method, Proc.new {})
36
- end
37
- end
38
-
39
- send(name).destroy_all
40
- end
14
+
15
+ def configure_dependency
16
+ return unless options[:dependent]
17
+ unless options[:dependent].in?([:destroy]) # Only destroy and restrict supported for now
18
+ fail ArgumentError,
19
+ "The :dependent option only handles :destroy or :restrict for now (#{options[:dependent].inspect})"
41
20
  end
42
-
43
- def define_restrict_dependency_method
44
- name = self.name
45
- mixin.redefine_method(dependency_method_name) do
46
- raise DatastaxRails::DeleteRestrictionError.new(name) unless send(name).empty?
21
+
22
+ send("define_#{options[:dependent]}_dependency_method")
23
+ model.before_destroy dependency_method_name
24
+ end
25
+
26
+ def define_destroy_dependency_method
27
+ name = self.name
28
+ mixin.redefine_method(dependency_method_name) do
29
+ send(name).each do |o|
30
+ # No point in executing the counter update since we're going to destroy the parent anyway
31
+ counter_method = ('belongs_to_counter_cache_before_destroy_for_' + self.class.name.downcase).to_sym
32
+ next unless o.respond_to?(counter_method)
33
+ class << o
34
+ self
35
+ end.send(:define_method, counter_method, proc {})
47
36
  end
37
+
38
+ send(name).destroy_all
48
39
  end
49
-
50
- def dependency_method_name
51
- "has_many_dependent_for_#{name}"
40
+ end
41
+
42
+ def define_restrict_dependency_method
43
+ name = self.name
44
+ mixin.redefine_method(dependency_method_name) do
45
+ fail DatastaxRails::DeleteRestrictionError.new(name) unless send(name).empty?
52
46
  end
47
+ end
48
+
49
+ def dependency_method_name
50
+ "has_many_dependent_for_#{name}"
51
+ end
53
52
  end
54
- end
53
+ end
@@ -1,4 +1,4 @@
1
- module DatastaxRails::Associations::Builder
1
+ module DatastaxRails::Associations::Builder # rubocop:disable Style/ClassAndModuleChildren
2
2
  class HasOne < SingularAssociation #:nodoc:
3
3
  self.macro = :has_one
4
4
 
@@ -10,43 +10,42 @@ module DatastaxRails::Associations::Builder
10
10
 
11
11
  private
12
12
 
13
- def validate_options
14
- valid_options = self.class.valid_options
15
- valid_options += self.class.through_options if options[:through]
16
- options.assert_valid_keys(valid_options)
17
- end
18
-
19
- def configure_dependency
20
- if options[:dependent]
21
- unless options[:dependent].in?([:destroy, :delete, :nullify, :restrict])
22
- raise ArgumentError, "The :dependent option expects either :destroy, :delete, " \
23
- ":nullify or :restrict (#{options[:dependent].inspect})"
24
- end
13
+ def validate_options
14
+ valid_options = self.class.valid_options
15
+ valid_options += self.class.through_options if options[:through]
16
+ options.assert_valid_keys(valid_options)
17
+ end
25
18
 
26
- send("define_#{options[:dependent]}_dependency_method")
27
- model.before_destroy dependency_method_name
28
- end
19
+ def configure_dependency
20
+ return unless options[:dependent]
21
+ unless options[:dependent].in?([:destroy, :delete, :nullify, :restrict])
22
+ fail ArgumentError, 'The :dependent option expects either :destroy, :delete, ' \
23
+ ":nullify or :restrict (#{options[:dependent].inspect})"
29
24
  end
30
25
 
31
- def dependency_method_name
32
- "has_one_dependent_#{options[:dependent]}_for_#{name}"
33
- end
26
+ send("define_#{options[:dependent]}_dependency_method")
27
+ model.before_destroy dependency_method_name
28
+ end
34
29
 
35
- def define_destroy_dependency_method
36
- model.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
30
+ def dependency_method_name
31
+ "has_one_dependent_#{options[:dependent]}_for_#{name}"
32
+ end
33
+
34
+ def define_destroy_dependency_method
35
+ model.send(:class_eval, <<-eoruby, __FILE__, __LINE__ + 1)
37
36
  def #{dependency_method_name}
38
37
  association(#{name.to_sym.inspect}).delete
39
38
  end
40
39
  eoruby
40
+ end
41
+ alias_method :define_delete_dependency_method, :define_destroy_dependency_method
42
+ alias_method :define_nullify_dependency_method, :define_destroy_dependency_method
43
+
44
+ def define_restrict_dependency_method
45
+ name = self.name
46
+ model.redefine_method(dependency_method_name) do
47
+ fail DatastaxRails::DeleteRestrictionError.new(name) unless send(name).nil?
41
48
  end
42
- alias :define_delete_dependency_method :define_destroy_dependency_method
43
- alias :define_nullify_dependency_method :define_destroy_dependency_method
44
-
45
- def define_restrict_dependency_method
46
- name = self.name
47
- model.redefine_method(dependency_method_name) do
48
- raise DatastaxRails::DeleteRestrictionError.new(name) unless send(name).nil?
49
- end
50
- end
49
+ end
51
50
  end
52
- end
51
+ end