Permalink
Browse files

Allow access to assigned_attributes

  • Loading branch information...
1 parent b4cdaef commit 78e2fb3150b4a6f64734b652149e58333cd429f8 @eeng committed Mar 22, 2013
Showing with 10 additions and 6 deletions.
  1. +2 −2 lib/machinist/blueprint.rb
  2. +1 −0 lib/machinist/lathe.rb
  3. +7 −4 lib/machinist/overrides.rb
View
4 lib/machinist/blueprint.rb
@@ -22,8 +22,8 @@ def initialize(klass, options = {}, &block)
# Pass in attributes to override values defined in the blueprint.
def make(attributes = {})
# Collect overrides from the hierarchy
- overrided_attributes = OverridedAttributes.get_from &@block
- each_ancestor { |blueprint| overrided_attributes += OverridedAttributes.get_from(&blueprint.block) }
+ overrided_attributes = OverridedAttributes.get_from attributes, &@block
+ each_ancestor { |blueprint| overrided_attributes += OverridedAttributes.get_from(attributes, &blueprint.block) }
lathe = lathe_class.new(@klass, new_serial_number, attributes, overrided_attributes)
View
1 lib/machinist/lathe.rb
@@ -6,6 +6,7 @@ module Machinist
# The Lathe implements all the methods that are available to the blueprint,
# including method_missing to let the blueprint define attributes.
class Lathe
+ attr_reader :assigned_attributes
def initialize(klass, serial_number, attributes = {}, overrided_attributes = {})
@klass = klass
View
11 lib/machinist/overrides.rb
@@ -11,13 +11,16 @@ def method_missing(attribute, *args, &block) #:nodoc:
end
end
- class OverridedAttributes
- def initialize
+ class OverridedAttributes
+ attr_reader :assigned_attributes
+
+ def initialize attributes
@accumulator = Accumulator.new
+ @assigned_attributes = attributes
end
- def self.get_from &block
- new.tap { |oa| oa.instance_eval(&block) }.attributes
+ def self.get_from attributes, &block
+ new(attributes).tap { |oa| oa.instance_eval(&block) }.attributes
end
def method_missing(attribute, *args, &block) #:nodoc:

0 comments on commit 78e2fb3

Please sign in to comment.