module EDSL
Top level module for the gem
Constants
- VERSION
Public Class Methods
add_resolvers(cls)
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/edsl/dsl.rb, line 26 def self.add_resolvers(cls) cls.send(:define_method, :resolve_with) do |with_var| return with_var.call if with_var.is_a?(Proc) return self if with_var == :parent return :self if with_var == :element with_var end cls.send(:define_method, :resolve_context) do |context| return context.call if context.is_a?(Proc) return self.send(context) if context.is_a?(Symbol) context end end
alias_accessor(new_name, acc_name)
click to toggle source
Allow an accessor to be accessed by a different name
# File lib/edsl/dsl.rb, line 54 def self.alias_accessor(new_name, acc_name) DSL.alias_accessor(new_name, acc_name) end
define_accessor(acc_name, default_opts)
click to toggle source
Define a new accessor using a name and options. See the DSL
module for more info
# File lib/edsl/dsl.rb, line 49 def self.define_accessor(acc_name, default_opts) DSL.define_accessor(acc_name, default_opts) end
define_accessors(accessor_array)
click to toggle source
Allow multiple accessors to be defined at once
# File lib/edsl/dsl.rb, line 59 def self.define_accessors(accessor_array) DSL.define_accessors(accessor_array) end
extend_dsl(&block)
click to toggle source
Use a block to add new methods to the DSL
.
# File lib/edsl/dsl.rb, line 43 def self.extend_dsl(&block) EDSL::DSL.class_eval(&block) end
included(cls)
click to toggle source
Ensure the DSL
methods are applied when we're included
# File lib/edsl/dsl.rb, line 9 def self.included(cls) cls.extend EDSL::DSL add_resolvers(cls) cls.send(:define_method, :apply_hooks) do |hook_defs, element| return nil if element.nil? return element if hook_defs.nil? hd = hook_defs.dup hd.hooks.each { |hook| hook.call_chain.each { |cc| cc.resolve_with { |c| resolve_with(c) } } } hd.hooks.each { |hook| hook.call_chain.each { |cc| cc.resolve_contexts { |c| resolve_context(c) } } } CptHook::Hookable.new(element, hd, self) end end