lib/prezzo/composable.rb in prezzo-0.4.0 vs lib/prezzo/composable.rb in prezzo-0.4.1

- old
+ new

@@ -7,15 +7,27 @@ end module ClassMethods def composed_by(options) options.each do |name, klass| - options[name] = klass + components << name define_method(name) do - options[name].new(context).calculate + cached_components[name] ||= klass.new(context) + + cached_components[name].calculate end end end + + def components + @components ||= [] + end + end + + private + + def cached_components + @cached_components ||= {} end end end