Skip to content

Commit

Permalink
Remove ObjectWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Dec 30, 2011
1 parent 3eccbc5 commit 148c3ec
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions lib/factory_girl/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ module FactoryGirl
class Proxy #:nodoc:
def initialize(klass, callbacks = [])
@callbacks = process_callbacks(callbacks)
@proxy = ObjectWrapper.new(klass, self)
@klass = klass

@evaluator_class_definer = EvaluatorClassDefiner.new
end

delegate :set, :to => :@proxy
delegate :set, :to => :@evaluator_class_definer

def run_callbacks(name)
if @callbacks[name]
@callbacks[name].each do |callback|
callback.run(result_instance, @proxy.anonymous_instance)
callback.run(result_instance, anonymous_instance)
end
end
end
Expand Down Expand Up @@ -77,45 +79,19 @@ def process_callbacks(callbacks)
end

def result_instance
@proxy.object
attribute_assigner.object
end

def result_hash
@proxy.to_hash
attribute_assigner.hash
end

class ObjectWrapper
def initialize(klass, proxy)
@klass = klass
@proxy = proxy
@assigned_attributes = []

@evaluator_class_definer = EvaluatorClassDefiner.new
end

delegate :set, :attributes, :to => :@evaluator_class_definer

def to_hash
attribute_assigner.hash
end

def object
attribute_assigner.object
end

def anonymous_instance
@anonymous_instance ||= @evaluator_class_definer.evaluator_class.new(@proxy)
end

private

def get(attribute)
anonymous_instance.send(attribute)
end
def anonymous_instance
@anonymous_instance ||= @evaluator_class_definer.evaluator_class.new(self)
end

def attribute_assigner
@attribute_assigner ||= AttributeAssigner.new(@klass, anonymous_instance, attributes)
end
def attribute_assigner
@attribute_assigner ||= AttributeAssigner.new(@klass, anonymous_instance, @evaluator_class_definer.attributes)
end
end
end

0 comments on commit 148c3ec

Please sign in to comment.