Skip to content

Commit

Permalink
Removing decorator for method missing - cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Dec 10, 2009
1 parent be8e32f commit 7f1ea0c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 72 deletions.
12 changes: 9 additions & 3 deletions lib/mongoid/associations/belongs_to.rb
Expand Up @@ -2,7 +2,9 @@
module Mongoid #:nodoc:
module Associations #:nodoc:
class BelongsTo #:nodoc:
include Decorator

delegate :==, :to => :document
attr_reader :document, :options

# Creates the new association by setting the internal
# document as the passed in Document. This should be the
Expand All @@ -16,8 +18,7 @@ class BelongsTo #:nodoc:
# document: The parent +Document+
# options: The association options
def initialize(document, options)
@document = document
decorate!
@document, @options = document, options
end

# Returns the parent document. The id param is present for
Expand All @@ -27,6 +28,11 @@ def find(id)
@document
end

# Delegate all missing methods over to the parent +Document+.
def method_missing(name, *args)
@document.send(name, *args)
end

class << self
# Creates the new association by setting the internal
# document as the passed in Document. This should be the
Expand Down
27 changes: 0 additions & 27 deletions lib/mongoid/associations/decorator.rb

This file was deleted.

13 changes: 7 additions & 6 deletions lib/mongoid/associations/has_one.rb
Expand Up @@ -2,16 +2,13 @@
module Mongoid #:nodoc:
module Associations #:nodoc:
class HasOne #:nodoc:
include Decorator

delegate :valid?, :to => :document

attr_accessor :parent, :options
delegate :==, :to => :document
attr_reader :document, :parent, :options

# Build a new object for the association.
def build(attributes)
@document = attributes.assimilate(@parent, @options)
decorate!
self
end

Expand All @@ -38,10 +35,14 @@ def initialize(document, attributes, options)
@parent, @options = document, options
unless attributes.nil?
@document = attributes.assimilate(@parent, @options)
decorate!
end
end

# Delegate all missing methods over to the +Document+.
def method_missing(name, *args)
@document.send(name, *args)
end

class << self
# Preferred method of instantiating a new +HasOne+, since nil values
# will be handled properly.
Expand Down
36 changes: 0 additions & 36 deletions spec/unit/mongoid/associations/decorator_spec.rb

This file was deleted.

0 comments on commit 7f1ea0c

Please sign in to comment.