Permalink
Browse files

extract duplicate code into many association

  • Loading branch information...
1 parent 534648a commit d5907d3ff748b334c3ecbc169867133df5c17e3a @ananthakumaran ananthakumaran committed with Mar 23, 2012
@@ -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'
@@ -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
@@ -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
@@ -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

0 comments on commit d5907d3

Please sign in to comment.