lib/compositor/base.rb in compositor-0.1.3 vs lib/compositor/base.rb in compositor-0.1.4

- old
+ new

@@ -1,6 +1,8 @@ module Compositor + class MethodAlreadyDefinedError < RuntimeError; end + class Base attr_reader :attrs attr_accessor :root, :context def initialize(view_context, attrs = {}) @@ -39,10 +41,14 @@ klazz.name.gsub(/(.*::)|(Compositor$)/, '').underscore end def self.inherited(subclass) method_name = root_class_name(subclass) - unless method_name.eql?("base") # check if it's already defined + unless method_name.eql?("base") || method_name.start_with?("abstract") + # check if it's already defined + if Compositor::DSL.instance_methods.include?(method_name.to_sym) + raise MethodAlreadyDefinedError.new("Method #{method_name} is already defined on the DSL class.") + end Compositor::DSL.send(:define_method, method_name) do |*args, &block| subclass. new(@context, *args). dsl(self, &block) end