lib/compositor/leaf.rb in compositor-0.1.1 vs lib/compositor/leaf.rb in compositor-0.1.3

- old
+ new

@@ -1,17 +1,8 @@ module Compositor class Leaf < Compositor::Base - attr_accessor :object - def initialize(view_context, object = {}, args = {}) - if object.is_a?(::Hash) - super(view_context, object) - else - super(view_context, {object: object}.merge!(args)) - end - end - def root if @root.is_a?(Symbol) super elsif @root root_class_name.to_sym @@ -22,22 +13,15 @@ def composite? false end - def self.inherited(subclass) - method_name = root_class_name(subclass) - unless method_name.eql?("base") - Compositor::DSL.send(:define_method, method_name) do |*args| - leaf = subclass.new(@view_context, *args) - if self.generator - raise "Leaves should be called within composite" unless self.generator.composite? - self.generator.collection << leaf - else - self.generator = leaf - end - leaf - end + def dsl(dsl) + if dsl.generator + raise "Leaves should be called within composite" unless dsl.generator.composite? + dsl.generator.collection << self + else + dsl.generator = self end end end end