Module: EDSL
- Included in:
- ElementContainer
- Defined in:
- lib/edsl/dsl.rb,
lib/edsl/version.rb,
lib/edsl/watir_elements.rb,
lib/edsl/element_container.rb
Overview
Top level module for the gem
Defined Under Namespace
Modules: DSL, WatirElements Classes: ElementContainer
Constant Summary collapse
- VERSION =
'0.4.0'.freeze
Class Method Summary collapse
-
.add_resolvers(cls) ⇒ Object
rubocop:enable Metrics/AbcSize.
-
.alias_accessor(new_name, acc_name) ⇒ Object
Allow an accessor to be accessed by a different name.
-
.define_accessor(acc_name, default_opts) ⇒ Object
Define a new accessor using a name and options.
-
.define_accessors(accessor_array) ⇒ Object
Allow multiple accessors to be defined at once.
-
.extend_dsl(&block) ⇒ Object
Use a block to add new methods to the DSL.
-
.included(cls) ⇒ Object
Ensure the DSL methods are applied when we’re included.
Class Method Details
.add_resolvers(cls) ⇒ Object
rubocop:enable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
Allow an accessor to be accessed by a different name
54 55 56 |
# 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) ⇒ Object
Define a new accessor using a name and options. See the DSL module for more info
49 50 51 |
# 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) ⇒ Object
Allow multiple accessors to be defined at once
59 60 61 |
# File 'lib/edsl/dsl.rb', line 59 def self.define_accessors(accessor_array) DSL.define_accessors(accessor_array) end |
.extend_dsl(&block) ⇒ Object
Use a block to add new methods to the DSL.
43 44 45 |
# File 'lib/edsl/dsl.rb', line 43 def self.extend_dsl(&block) EDSL::DSL.class_eval(&block) end |
.included(cls) ⇒ Object
Ensure the DSL methods are applied when we’re included
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |