Skip to content

Commit

Permalink
Revert "delay pushing an instance on to a collection until it's been …
Browse files Browse the repository at this point in the history
…completely initialized (i.e. if there's an instance scope, assigning values to attributes), got stung by this, and i think conceptually you do want to delay pushing onto a collection until the instance is completely initialized... but we'll see, that's for sure"

This reverts commit 24fd885.

This was a bad idea, broke our production. Need to figure out how and if this is a problem that needs solving :( Gah!
  • Loading branch information
ryan-allen committed Dec 1, 2008
1 parent 24fd885 commit 091c879
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
4 changes: 3 additions & 1 deletion lumberjack.rb
Expand Up @@ -73,19 +73,21 @@ def method_missing(*args, &block)
end
else # scope is an Array, so create an Instance
klass = args.shift
# :w

if @bits and @bits.any?
module_scope = @bits.collect { |bit| classify bit.to_s }.join('::')
instance = eval("#{module_scope}::#{classify klass.to_s}").new(*args)
@bits = nil
else
instance = eval(classify(klass.to_s)).new(*args)
end
current_scope << instance # add this instance to the scoped Array
if block # we got a block, change scope to set accessors
append_scope_with instance
instance_eval(&block)
jump_out_of_scope
end
current_scope << instance # add this instance to the scoped Array (after attrs have been set)
end
end
end
Expand Down
23 changes: 1 addition & 22 deletions lumberjack_test.rb
Expand Up @@ -31,25 +31,13 @@ def initialize(args = {:name => 'A Car, ya mum'})
end

class SetOfWheels < Array
def <<(wheel)
super(wheel) unless wheel.worn_out? # test that we completely construct an object prior to pushing it
end
end

class Wheel
attr_accessor :wear
def initialize(args = {})
def initialize(args)
@wear = args[:wear]
end

def worn_out?
if @wear
false
else
raise "i was expecting @wear to be set!!!" # for testing delayed push
end
end

end

# tree = Lumberjack.construct do # create a list
Expand Down Expand Up @@ -227,14 +215,5 @@ def test_we_got_backslashes_that_resolve_scope_or_something
assert_kind_of Vehicle::Heavy, cars[1]
assert_kind_of Vehicle::Heavy::ReallyHeavy, cars[2]
end

def test_we_fully_initialize_an_object_prior_to_pushing_it_onto_something
Lumberjack.construct SetOfWheels.new do
wheel do
wear :none # delayed attribute setting, if it's pushed early it'll raise an exception
# as per the array implentation of <<
end
end
end

end

0 comments on commit 091c879

Please sign in to comment.