lib/compositor/base.rb in compositor-1.0.1 vs lib/compositor/base.rb in compositor-2.0.0
- old
+ new
@@ -1,7 +1,8 @@
module Compositor
- class MethodAlreadyDefinedError < RuntimeError; end
+ class MethodAlreadyDefinedError < RuntimeError;
+ end
class Base
attr_reader :attrs
attr_accessor :root, :context
@@ -31,20 +32,16 @@
def include_root?
self.root ? true : false
end
- def root_class_name
- self.class.root_class_name(self.class)
+ def self.original_dsl_name
+ self.name.gsub(/(Compositor$)/, '').gsub(/::/, '_').underscore
end
- def self.root_class_name(klazz)
- klazz.name.gsub(/(.*::)|(Compositor$)/, '').underscore
- end
-
def self.inherited(subclass)
- method_name = root_class_name(subclass)
+ method_name = subclass.original_dsl_name
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
@@ -63,8 +60,8 @@
end
require_relative 'dsl'
require_relative 'composite'
require_relative 'leaf'
-require_relative 'literal'
-require_relative 'list'
-require_relative 'map'
+require_relative 'compositors/literal_compositor'
+require_relative 'compositors/list_compositor'
+require_relative 'compositors/map_compositor'