class Compositor::Base
Attributes
attrs[R]
context[RW]
root[RW]
Public Class Methods
inherited(subclass)
click to toggle source
# File lib/compositor/base.rb, line 41 def self.inherited(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 Compositor::DSL.send(:define_method, method_name) do |*args, &block| subclass. new(@context, *args). dsl(self, &block) end end end
new(view_context, attrs = {})
click to toggle source
# File lib/compositor/base.rb, line 9 def initialize(view_context, attrs = {}) @attrs = attrs self.context = view_context attrs.each_pair do |key, value| self.send("#{key}=", value) end end
original_dsl_name()
click to toggle source
# File lib/compositor/base.rb, line 37 def self.original_dsl_name self.name.gsub(/(Compositor$)/, '').gsub(/::/, '_').underscore end
Public Instance Methods
dsl()
click to toggle source
# File lib/compositor/base.rb, line 56 def dsl raise "Implement in subclasses" end
include_root?()
click to toggle source
# File lib/compositor/base.rb, line 33 def include_root? self.root ? true : false end
to_h()
click to toggle source
# File lib/compositor/base.rb, line 25 def to_h to_hash end
to_hash()
click to toggle source
# File lib/compositor/base.rb, line 17 def to_hash raise NotImplementedError.new("Abstract method, should be implemented by subclasses") end
to_json(options = {})
click to toggle source
# File lib/compositor/base.rb, line 29 def to_json(options = {}) Oj.dump(to_hash) end
with_root_element() { || ... }
click to toggle source
# File lib/compositor/base.rb, line 21 def with_root_element include_root? ? {root => yield} : yield end