Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract duplicate code into many association

  • Loading branch information...
commit d5907d3ff748b334c3ecbc169867133df5c17e3a 1 parent 534648a
Anantha Kumaran ananthakumaran authored committed
1  lib/dynamoid/associations.rb
View
@@ -1,6 +1,7 @@
# encoding: utf-8
require 'dynamoid/associations/association'
require 'dynamoid/associations/single_association'
+require 'dynamoid/associations/many_association'
require 'dynamoid/associations/has_many'
require 'dynamoid/associations/belongs_to'
require 'dynamoid/associations/has_one'
25 lib/dynamoid/associations/has_and_belongs_to_many.rb
View
@@ -4,28 +4,9 @@ module Dynamoid #:nodoc:
# The has and belongs to many association.
module Associations
class HasAndBelongsToMany
- include Dynamoid::Associations::Association
-
- # Is this array equal to the association's records?
- #
- # @return [Boolean] true/false
- #
- # @since 0.2.0
- def ==(other)
- records == Array(other)
- end
-
- # Delegate methods we don't find directly to the records array.
- #
- # @since 0.2.0
- def method_missing(method, *args)
- if records.respond_to?(method)
- records.send(method, *args)
- else
- super
- end
- end
-
+ include Association
+ include ManyAssociation
+
private
# Find the target association, always another :has_and_belongs_to_many association. Uses either options[:inverse_of] or the source class name
23 lib/dynamoid/associations/has_many.rb
View
@@ -4,27 +4,8 @@ module Dynamoid #:nodoc:
# The has_many association.
module Associations
class HasMany
- include Dynamoid::Associations::Association
-
- # Is this array equal to the association's records?
- #
- # @return [Boolean] true/false
- #
- # @since 0.2.0
- def ==(other)
- records == Array(other)
- end
-
- # Delegate methods we don't find directly to the records array.
- #
- # @since 0.2.0
- def method_missing(method, *args)
- if records.respond_to?(method)
- records.send(method, *args)
- else
- super
- end
- end
+ include Association
+ include ManyAssociation
private
28 lib/dynamoid/associations/many_association.rb
View
@@ -0,0 +1,28 @@
+# encoding: utf-8
+module Dynamoid #:nodoc:
+
+ module Associations
+ module ManyAssociation
+
+ # Is this array equal to the association's records?
+ #
+ # @return [Boolean] true/false
+ #
+ # @since 0.2.0
+ def ==(other)
+ records == Array(other)
+ end
+
+ # Delegate methods we don't find directly to the records array.
+ #
+ # @since 0.2.0
+ def method_missing(method, *args)
+ if records.respond_to?(method)
+ records.send(method, *args)
+ else
+ super
+ end
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.