Module: SeleniumRecord::ComponentAutoload
- Included in:
- Base
- Defined in:
- lib/selenium_record/component_autoload.rb
Overview
Provides shortcuts for selenium object creation
Defined Under Namespace
Modules: ClassMethods
Classes: UnknownComponent
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Proxies all calls to component methods
86
87
88
89
90
91
92
|
# File 'lib/selenium_record/component_autoload.rb', line 86
def method_missing(method, *args)
[*@components].each do |comp|
return comp.send(method, *args) if comp.respond_to?(method)
end
rescue UnknownComponent
super
end
|
Class Method Details
.component_loader(component_type, _, opts = {}) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/selenium_record/component_autoload.rb', line 52
def self.component_loader(component_type, _, opts = {})
mod = self
define_method "#{component_type}_for" do |item|
record_opts = mod.(component_type, self.class, {
subject: item.to_s.camelize,
suffixes: %w(View)
}.merge(opts))
create_record(object, record_opts).tap(&:load_dom)
end
end
|
25
26
27
28
29
30
31
32
|
# File 'lib/selenium_record/component_autoload.rb', line 25
def self.(klass_name, opts = {})
return unless opts[:nested_folder]
suffixes = [*opts[:suffixes]]
suffixes.map do |suffix|
match_data = Regexp.new("^(.*)#{suffix}$").match(klass_name)
match_data[1] if match_data
end.compact.first
end
|
Returns the module containing the classes for the marker type group.
18
19
20
21
22
|
# File 'lib/selenium_record/component_autoload.rb', line 18
def self.(*modules)
modules.compact.reduce(Configuration.objects_module) do |klass, sym|
klass.const_get(sym)
end
end
|
38
39
40
41
42
43
|
# File 'lib/selenium_record/component_autoload.rb', line 38
def self.(component_type, klass, opts = {})
suffix = component_type.to_s.capitalize
group = (klass.name.split('::').last, opts)
namespace = (suffix.pluralize, group)
{ namespace: namespace, suffix: suffix, subject: opts[:subject] }
end
|
.included(base) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/selenium_record/component_autoload.rb', line 8
def self.included(base)
base.extend(ClassMethods)
base.instance_eval do
attr_reader :components
end
end
|
Instance Method Details
73
|
# File 'lib/selenium_record/component_autoload.rb', line 73
component_loader :modal, 'SeleniumRecord::Base'
|
67
68
|
# File 'lib/selenium_record/component_autoload.rb', line 67
component_loader :panel, 'SeleniumRecord::Base', nested_folder: true,
suffixes: %w(Pill)
|
#pill_for(pill_sym) ⇒ SeleniumObjects::Pills::ApplicationPill
71
72
|
# File 'lib/selenium_record/component_autoload.rb', line 71
component_loader :pill, 'SeleniumObjects::Pills::ApplicationPill',
nested_folder: true, suffixes: %w(Tab)
|
#tab_for(tab_sym) ⇒ SeleniumObjects::Tabs::ApplicationTab
69
70
|
# File 'lib/selenium_record/component_autoload.rb', line 69
component_loader :tab, 'SeleniumObjects::Tabs::ApplicationTab',
nested_folder: true
|
#view_for(model, opts = {}) ⇒ SeleniumObject::View::ApplicationView
80
81
82
83
|
# File 'lib/selenium_record/component_autoload.rb', line 80
def view_for(model, opts = {})
view_options = opts.merge namespace: so_module(:views), suffix: 'View'
create_record(model, view_options).tap(&:load_dom)
end
|