Class: PageEz::Page
- Inherits:
-
Object
- Object
- PageEz::Page
- Defined in:
- lib/page_ez/page.rb
Class Method Summary collapse
- .base_selector(value) ⇒ Object
- .constructor_from_block(superclass = nil, &block) ⇒ Object
- .contains(page_object, only: nil) ⇒ Object
- .delegate ⇒ Object
- .has_many(name, *args, **options, &block) ⇒ Object
- .has_many_ordered(name, *args, **options, &block) ⇒ Object
- .has_one(name, *args, **options, &block) ⇒ Object
- .inherited(subclass) ⇒ Object
- .logged_define_method(name, &block) ⇒ Object
- .method_added(name) ⇒ Object
- .method_undefined(name) ⇒ Object
- .rename_method(from:, to:) ⇒ Object
Instance Method Summary collapse
- #container ⇒ Object
-
#initialize(container = nil) ⇒ Page
constructor
A new instance of Page.
Constructor Details
#initialize(container = nil) ⇒ Page
Returns a new instance of Page.
44 45 46 47 48 |
# File 'lib/page_ez/page.rb', line 44 def initialize(container = nil) @container = container || Class.new do include Capybara::DSL end.new end |
Class Method Details
.base_selector(value) ⇒ Object
25 26 27 |
# File 'lib/page_ez/page.rb', line 25 def self.base_selector(value) self.container_base_selector = value end |
.constructor_from_block(superclass = nil, &block) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/page_ez/page.rb', line 137 def self.constructor_from_block(superclass = nil, &block) if block self.nested_macro = true Class.new(superclass || self).tap do |klass| visitor.begin_block_evaluation klass.macro_registrar = {} klass.class_eval(&block) visitor.end_block_evaluation self.nested_macro = false end elsif superclass superclass else Class.new(BasicObject) do def self.new(value) value end end end end |
.contains(page_object, only: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/page_ez/page.rb', line 29 def self.contains(page_object, only: nil) delegation_target = :"__page_object_#{page_object.object_id}__" has_one(delegation_target, page_object) if only methods_delegated_that_do_not_exist = only - page_object.instance_methods(false) if methods_delegated_that_do_not_exist.any? raise NoMethodError, "Attempting to delegate non-existent method(s) to #{page_object}: #{methods_delegated_that_do_not_exist.join(", ")}" end end delegate(*(only || page_object.instance_methods(false)), to: delegation_target) end |
.delegate ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/page_ez/page.rb', line 58 def self.delegate(...) super(...).tap do |method_names| method_names.each do |method_name| visitor.track_method_delegated(method_name) end end end |
.has_many(name, *args, **options, &block) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/page_ez/page.rb', line 95 def self.has_many(name, *args, **, &block) construction_strategy = case [args.length, args.first] in [2, _] then MethodGenerators::HasManyStaticSelector.new(name, args.first.to_s, args[1], , &block) in [1, String] | [1, Symbol] then MethodGenerators::HasManyStaticSelector.new(name, args.first.to_s, nil, , &block) in [0, _] then MethodGenerators::HasManyDynamicSelector.new(name, , &block) end visitor.process_macro(:has_many, name, construction_strategy) construction_strategy.run(self) self.macro_registrar = macro_registrar.merge(name => construction_strategy) end |
.has_many_ordered(name, *args, **options, &block) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/page_ez/page.rb', line 112 def self.has_many_ordered(name, *args, **, &block) construction_strategy = case [args.length, args.first] in [2, _] then MethodGenerators::HasManyOrderedSelector.new(name, args.first.to_s, args[1], , &block) in [1, String] | [1, Symbol] then MethodGenerators::HasManyOrderedSelector.new(name, args.first.to_s, nil, , &block) in [0, _] then MethodGenerators::HasManyOrderedDynamicSelector.new(name, , &block) end visitor.process_macro(:has_many_ordered, name, construction_strategy) construction_strategy.run(self) self.macro_registrar = macro_registrar.merge(name => construction_strategy) end |
.has_one(name, *args, **options, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/page_ez/page.rb', line 76 def self.has_one(name, *args, **, &block) construction_strategy = case [args.length, args.first] in [2, _] then MethodGenerators::HasOneStaticSelector.new(name, args.first.to_s, args[1], , &block) in [1, Class] then MethodGenerators::HasOneComposedClass.new(name, args.first, , &block) in [1, String] | [1, Symbol] then MethodGenerators::HasOneStaticSelector.new(name, args.first.to_s, nil, , &block) in [0, _] then MethodGenerators::HasOneDynamicSelector.new(name, , &block) end visitor.process_macro(:has_one, name, construction_strategy) construction_strategy.run(self) self.macro_registrar = macro_registrar.merge(name => construction_strategy) end |
.inherited(subclass) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/page_ez/page.rb', line 129 def self.inherited(subclass) if !nested_macro visitor.reset end visitor.inherit_from(subclass) end |
.logged_define_method(name, &block) ⇒ Object
158 159 160 161 |
# File 'lib/page_ez/page.rb', line 158 def self.logged_define_method(name, &block) visitor.define_method(name) define_method(name, &block) end |
.method_added(name) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/page_ez/page.rb', line 50 def self.method_added(name) visitor.track_method_added(name, macro_registrar[name]) if macro_registrar.key?(name) macro_registrar[name].run(self) end end |
.method_undefined(name) ⇒ Object
66 67 68 |
# File 'lib/page_ez/page.rb', line 66 def self.method_undefined(name) visitor.track_method_undefined(name) end |
.rename_method(from:, to:) ⇒ Object
70 71 72 73 74 |
# File 'lib/page_ez/page.rb', line 70 def self.rename_method(from:, to:) alias_method to, from undef_method from visitor.track_method_renamed(from, to) end |
Instance Method Details
#container ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/page_ez/page.rb', line 17 def container if container_base_selector @container.find(container_base_selector) else @container end end |