lib/metatron/template.rb in metatron-0.2.8 vs lib/metatron/template.rb in metatron-0.3.0
- old
+ new
@@ -32,22 +32,27 @@
def self.initializers
@initializers ||= []
end
- private
+ def self.nearest_metatron_ancestor
+ return self if metatron_template_class?
- def run_initializers
- self.class.initializers.each { |initializer| send(initializer.to_sym) }
+ ancestors.find { _1.respond_to?(:metatron_template_class?) && _1.metatron_template_class? }
end
- def find_kind
- return self.class.name.split("::").last if metatron_template?
+ def self.metatron_template_class?
+ return true if name == "Metatron::Template"
+ return false if name.start_with?("Metatron::Templates::Concerns")
- self.class.ancestors.find { |klass| metatron_template?(klass) }.name.split("::").last
+ name.start_with?("Metatron::Templates::")
end
- def metatron_template?(klass = self)
- klass.name.include?("Metatron::Templates") && !klass.name.include?("Concerns")
+ private
+
+ def run_initializers
+ self.class.nearest_metatron_ancestor.initializers.each { send(_1.to_sym) }
end
+
+ def find_kind = self.class.nearest_metatron_ancestor.name.split("::").last
end
end