automation_object 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/automation_object.rb +22 -11
- data/lib/automation_object/blue_print.rb +13 -12
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +9 -8
- data/lib/automation_object/blue_print/composite/base.rb +5 -4
- data/lib/automation_object/blue_print/composite/custom_method.rb +8 -7
- data/lib/automation_object/blue_print/composite/element.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_array.rb +6 -5
- data/lib/automation_object/blue_print/composite/element_hash.rb +7 -6
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +7 -7
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +5 -4
- data/lib/automation_object/blue_print/composite/hook.rb +9 -11
- data/lib/automation_object/blue_print/composite/hook_action.rb +25 -24
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +14 -13
- data/lib/automation_object/blue_print/composite/modal.rb +11 -21
- data/lib/automation_object/blue_print/composite/screen.rb +22 -16
- data/lib/automation_object/blue_print/composite/top.rb +13 -12
- data/lib/automation_object/blue_print/composite/view.rb +27 -16
- data/lib/automation_object/blue_print/hash_adapter.rb +15 -11
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +12 -11
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +28 -25
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/element.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +10 -9
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +11 -10
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +20 -25
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +15 -14
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +19 -24
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +8 -5
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +7 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +28 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +12 -13
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +9 -8
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +27 -23
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +25 -21
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +14 -11
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +45 -47
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +24 -28
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +14 -13
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +23 -22
- data/lib/automation_object/blue_print/hash_adapter/top.rb +16 -15
- data/lib/automation_object/blue_print/hash_adapter/view.rb +58 -4
- data/lib/automation_object/blue_print/yaml_adapter.rb +33 -34
- data/lib/automation_object/driver.rb +15 -13
- data/lib/automation_object/driver/appium_adapter/driver.rb +47 -46
- data/lib/automation_object/driver/appium_adapter/element.rb +29 -96
- data/lib/automation_object/driver/base.rb +4 -2
- data/lib/automation_object/driver/common_selenium/driver.rb +60 -0
- data/lib/automation_object/driver/common_selenium/element.rb +107 -0
- data/lib/automation_object/driver/common_selenium/element_geometry.rb +86 -0
- data/lib/automation_object/driver/driver.rb +60 -30
- data/lib/automation_object/driver/element.rb +70 -15
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +88 -34
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +94 -16
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +29 -8
- data/lib/automation_object/driver/nokogiri_adapter/{backup/form.rb → form.rb} +19 -6
- data/lib/automation_object/driver/nokogiri_adapter/request.rb +17 -0
- data/lib/automation_object/driver/nokogiri_adapter/session.rb +94 -0
- data/lib/automation_object/driver/nokogiri_adapter/window.rb +86 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +36 -45
- data/lib/automation_object/driver/selenium_adapter/element.rb +15 -85
- data/lib/automation_object/dsl.rb +11 -28
- data/lib/automation_object/dsl/_base.rb +70 -0
- data/lib/automation_object/dsl/_proxy.rb +24 -0
- data/lib/automation_object/dsl/element.rb +34 -0
- data/lib/automation_object/dsl/element_array.rb +34 -0
- data/lib/automation_object/dsl/element_hash.rb +34 -0
- data/lib/automation_object/dsl/modal.rb +43 -0
- data/lib/automation_object/dsl/screen.rb +45 -0
- data/lib/automation_object/dsl/top.rb +25 -0
- data/lib/automation_object/framework.rb +28 -38
- data/lib/automation_object/helpers/composite.rb +30 -27
- data/lib/automation_object/helpers/composite_hook.rb +16 -15
- data/lib/automation_object/{blue_print/helpers/file_helper.rb → helpers/file.rb} +12 -12
- data/lib/automation_object/helpers/hash.rb +6 -5
- data/lib/automation_object/helpers/kernel.rb +11 -0
- data/lib/automation_object/helpers/{reflection_helper.rb → reflection.rb} +9 -8
- data/lib/automation_object/helpers/string.rb +25 -15
- data/lib/automation_object/{proxies → proxy}/mutex_proxy.rb +18 -21
- data/lib/automation_object/proxy/proxy.rb +23 -0
- data/lib/automation_object/proxy/throttle_proxy.rb +52 -0
- data/lib/automation_object/state.rb +11 -29
- data/lib/automation_object/state/{blue_print_adapter/composite.rb → composite/_base.rb} +35 -25
- data/lib/automation_object/state/{blue_print_adapter/helpers/element_helper.rb → composite/_common_element.rb} +11 -11
- data/lib/automation_object/state/composite/element.rb +22 -0
- data/lib/automation_object/state/composite/element_array.rb +27 -0
- data/lib/automation_object/state/composite/element_hash.rb +33 -0
- data/lib/automation_object/state/composite/element_proxy.rb +33 -0
- data/lib/automation_object/state/composite/helpers/window.rb +61 -0
- data/lib/automation_object/state/composite/helpers/window_manager.rb +60 -0
- data/lib/automation_object/state/composite/hook.rb +56 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_action.rb +10 -8
- data/lib/automation_object/state/composite/hook_actions/action_loop.rb +36 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_screen.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_to_previous_screen.rb +7 -5
- data/lib/automation_object/state/composite/hook_actions/close_modal.rb +29 -0
- data/lib/automation_object/state/composite/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/composite/hook_actions/element_requirement.rb +32 -0
- data/lib/automation_object/state/composite/hook_actions/new_screen.rb +35 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/possible_screen_changes.rb +8 -7
- data/lib/automation_object/state/composite/hook_actions/reset_screen.rb +14 -0
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/show_modal.rb +7 -5
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/sleep.rb +4 -2
- data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/wait_for_elements.rb +7 -5
- data/lib/automation_object/state/composite/modal.rb +45 -0
- data/lib/automation_object/state/composite/screen.rb +58 -0
- data/lib/automation_object/state/composite/top.rb +51 -0
- data/lib/automation_object/state/error.rb +45 -6
- data/lib/automation_object/state/session.rb +25 -23
- data/lib/automation_object/step_definitions.rb +5 -3
- data/lib/automation_object/step_definitions/element.rb +77 -0
- data/lib/automation_object/step_definitions/element_array.rb +135 -0
- data/lib/automation_object/step_definitions/element_hash.rb +126 -0
- data/lib/automation_object/step_definitions/screen.rb +62 -0
- data/lib/automation_object/step_definitions/{cache.rb → support/cache.rb} +8 -6
- data/lib/automation_object/step_definitions/support/element_array.rb +40 -0
- data/lib/automation_object/step_definitions/support/element_hash.rb +41 -0
- data/lib/automation_object/step_definitions/{parse.rb → support/parse.rb} +8 -6
- data/lib/automation_object/version.rb +2 -1
- metadata +203 -103
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +0 -41
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +0 -138
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +0 -83
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +0 -66
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +0 -52
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +0 -115
- data/lib/automation_object/dsl/blue_print_adapter.rb +0 -16
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +0 -54
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +0 -14
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +0 -23
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +0 -26
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +0 -19
- data/lib/automation_object/dsl/models.rb +0 -18
- data/lib/automation_object/dsl/proxies/element.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_array.rb +0 -16
- data/lib/automation_object/dsl/proxies/element_hash.rb +0 -16
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +0 -74
- data/lib/automation_object/dsl/proxies/modal.rb +0 -17
- data/lib/automation_object/dsl/proxies/screen.rb +0 -17
- data/lib/automation_object/dsl/proxies/top.rb +0 -17
- data/lib/automation_object/proxies/proxy.rb +0 -20
- data/lib/automation_object/proxies/throttle_proxy.rb +0 -57
- data/lib/automation_object/state/blue_print_adapter.rb +0 -16
- data/lib/automation_object/state/blue_print_adapter/element.rb +0 -20
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +0 -25
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +0 -28
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +0 -137
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +0 -39
- data/lib/automation_object/state/blue_print_adapter/hook.rb +0 -56
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +0 -35
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +0 -31
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +0 -19
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +0 -34
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +0 -37
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +0 -18
- data/lib/automation_object/state/blue_print_adapter/modal.rb +0 -26
- data/lib/automation_object/state/blue_print_adapter/screen.rb +0 -32
- data/lib/automation_object/state/blue_print_adapter/top.rb +0 -45
- data/lib/automation_object/step_definitions/action.rb +0 -21
- data/lib/automation_object/step_definitions/element/actions.rb +0 -87
- data/lib/automation_object/step_definitions/element/regex.rb +0 -24
- data/lib/automation_object/step_definitions/element/steps.rb +0 -67
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative '_base'
|
3
|
+
require_relative '_proxy'
|
4
|
+
|
5
|
+
require_relative 'screen'
|
6
|
+
|
7
|
+
module AutomationObject
|
8
|
+
module Dsl
|
9
|
+
# Top DSL Class
|
10
|
+
class Top < Base
|
11
|
+
has_many :screens, ScreenProxy
|
12
|
+
end
|
13
|
+
|
14
|
+
# Proxy for Top Composite
|
15
|
+
# Use proxy for methods trying to do a @state call
|
16
|
+
class TopProxy < Proxy
|
17
|
+
# @param [AutomationObject::BluePrint::Composite::Top] blue_prints
|
18
|
+
# @param [AutomationObject::State::Session] state
|
19
|
+
# @param [Symbol] name
|
20
|
+
def initialize(blue_prints, state, name)
|
21
|
+
super Top, blue_prints, state, name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'proxy/proxy'
|
2
3
|
require_relative 'blue_print'
|
3
4
|
require_relative 'driver'
|
4
5
|
require_relative 'dsl'
|
5
6
|
require_relative 'state'
|
6
7
|
|
7
8
|
module AutomationObject
|
8
|
-
#Framework class, the core
|
9
|
-
#A Proxy class that will become the DSL Framework
|
10
|
-
class Framework <
|
9
|
+
# Framework class, the core
|
10
|
+
# A Proxy class that will become the DSL Framework
|
11
|
+
class Framework < Proxy::Proxy
|
11
12
|
# @return [AutomationObject::BluePrint::Composite::Top]
|
12
13
|
attr_accessor :blue_prints
|
13
14
|
|
@@ -28,60 +29,49 @@ module AutomationObject
|
|
28
29
|
self.driver = driver
|
29
30
|
self.blue_prints = blue_prints
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
@subject = self.dsl
|
32
|
+
self.state = State.create(self.driver, self.blue_prints)
|
33
|
+
@subject = Dsl.create(self.blue_prints, state)
|
34
34
|
|
35
35
|
AutomationObject::Framework.singleton = self
|
36
36
|
end
|
37
37
|
|
38
|
-
# dsl get method
|
39
|
-
# @return [Dsl] workable dsl composite object
|
40
|
-
def dsl
|
41
|
-
@dsl ||= Dsl.new(blue_prints: self.blue_prints, state: self.state)
|
42
|
-
end
|
43
|
-
|
44
|
-
# state get method
|
45
|
-
# @return [State] state object which actively controls the ui state
|
46
|
-
def state
|
47
|
-
@state ||= State.new(self.blue_prints, self.driver)
|
48
|
-
end
|
49
|
-
|
50
38
|
# BluePrints (UI configurations) wrapped in an composite
|
51
39
|
# Composite provides a common interface for all adapters
|
52
40
|
# @param value [String, Hash] String to YAML files or Hash configuration
|
53
41
|
# @return [AutomationObject::BluePrint::Composite::Top] top composite object
|
42
|
+
undef :blue_prints= if defined? :blue_prints=
|
54
43
|
def blue_prints=(value)
|
55
44
|
case value
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
45
|
+
when String
|
46
|
+
BluePrint.adapter = :yaml
|
47
|
+
when Hash
|
48
|
+
BluePrint.adapter = :hash
|
60
49
|
end
|
61
50
|
|
62
|
-
@blue_prints = BluePrint.
|
51
|
+
@blue_prints = BluePrint.create(value)
|
63
52
|
end
|
64
53
|
|
65
54
|
# Driver port provides a formatted interface for interacting with different drivers
|
66
55
|
# @return [AutomationObject::Driver::Driver] driver interface object
|
56
|
+
undef :driver= if defined? :driver=
|
67
57
|
def driver=(value)
|
68
|
-
case value
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@driver = Driver.
|
58
|
+
Driver.adapter = case value
|
59
|
+
when Selenium::WebDriver::Driver
|
60
|
+
:selenium
|
61
|
+
when Appium::Driver
|
62
|
+
:appium
|
63
|
+
else
|
64
|
+
:nokogiri
|
65
|
+
end
|
66
|
+
|
67
|
+
@driver = Driver.create(value)
|
78
68
|
end
|
79
69
|
|
80
70
|
# Reset the entire state, remove any values
|
81
71
|
# Leave the driver alone here, can be done elsewhere
|
82
72
|
# @return [void]
|
83
73
|
def quit
|
84
|
-
|
74
|
+
state.quit # Quit the state. That way it knows to kill threads if operational
|
85
75
|
self.dsl, self.state, self.blue_prints, self.driver = nil
|
86
76
|
end
|
87
77
|
|
@@ -91,11 +81,11 @@ module AutomationObject
|
|
91
81
|
class << self
|
92
82
|
attr_accessor :singleton
|
93
83
|
|
94
|
-
#Singleton method if using Cucumber
|
84
|
+
# Singleton method if using Cucumber
|
95
85
|
# @return [Framework] singleton of self
|
96
86
|
def get
|
97
|
-
|
87
|
+
singleton
|
98
88
|
end
|
99
89
|
end
|
100
90
|
end
|
101
|
-
end
|
91
|
+
end
|
@@ -1,30 +1,33 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'reflection'
|
2
3
|
require_relative 'composite_hook'
|
3
4
|
|
4
5
|
module AutomationObject
|
5
|
-
#Composite is a super class that helps build composite objects based of a Hash
|
6
|
-
#Composite classes should inherit from this class and use the class-level methods to add the components
|
6
|
+
# Composite is a super class that helps build composite objects based of a Hash
|
7
|
+
# Composite classes should inherit from this class and use the class-level methods to add the components
|
7
8
|
class Composite
|
8
9
|
include CompositeHook
|
9
|
-
include
|
10
|
+
include Reflection
|
10
11
|
|
11
12
|
attr_accessor :name, :parent, :location, :children
|
12
13
|
|
13
14
|
# @param name [Symbol] name of the object
|
14
15
|
# @param parent [Object, nil] parent composite object
|
15
16
|
# @param location [String] string location for error/debugging purposes
|
16
|
-
def initialize(
|
17
|
+
def initialize(_name = :top, parent = nil, location = 'top')
|
17
18
|
self.parent = parent
|
18
19
|
self.location = location
|
19
20
|
|
20
|
-
|
21
|
+
before_create_run
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
add_has_one_relationships
|
24
|
+
add_has_many_relationships
|
24
25
|
|
25
|
-
|
26
|
+
after_create_run
|
26
27
|
end
|
27
28
|
|
29
|
+
# Remove getter to solve stupid Ruby warning
|
30
|
+
undef :children if method_defined? :children
|
28
31
|
def children
|
29
32
|
@children ||= {}
|
30
33
|
end
|
@@ -32,15 +35,15 @@ module AutomationObject
|
|
32
35
|
# Get top composite Object
|
33
36
|
# @return [AutomationObject::Composite]
|
34
37
|
def top
|
35
|
-
#Should recursively call top until parent is nil
|
36
|
-
|
38
|
+
# Should recursively call top until parent is nil
|
39
|
+
parent.nil? ? self : parent.top
|
37
40
|
end
|
38
41
|
|
39
42
|
# Abstract argument, override
|
40
43
|
# @param name [Symbol] name of child
|
41
44
|
# @param options [Hash] options for child
|
42
45
|
# @return child [Object] return child composite object
|
43
|
-
def get_child(
|
46
|
+
def get_child(_name, _options)
|
44
47
|
raise 'Abstract method'
|
45
48
|
end
|
46
49
|
|
@@ -48,48 +51,48 @@ module AutomationObject
|
|
48
51
|
# @param name [Symbol] name of child
|
49
52
|
# @param options [Hash] options for child
|
50
53
|
# @return children [Hash] return children and names
|
51
|
-
def get_children(
|
54
|
+
def get_children(_name, _options)
|
52
55
|
raise 'Abstract method'
|
53
56
|
end
|
54
57
|
|
55
58
|
def add_has_one_relationships
|
56
|
-
self.class.has_one_relationships.each
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
self.class.has_one_relationships.each do |name, options|
|
60
|
+
children[name] = get_child(name, options)
|
61
|
+
add_attribute(name, children[name])
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
def add_has_many_relationships
|
63
|
-
self.class.has_many_relationships.each
|
66
|
+
self.class.has_many_relationships.each do |name, options|
|
64
67
|
composite_children = get_children(name, options)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
children[name] = composite_children
|
69
|
+
add_attribute(name, children[name])
|
70
|
+
end
|
68
71
|
end
|
69
72
|
|
70
73
|
class << self
|
71
|
-
#Has many children relationship for the composite
|
74
|
+
# Has many children relationship for the composite
|
72
75
|
# @param children_name [Symbol] name of the children, should be a BluePrint method
|
73
76
|
# @param args [Hash] additional arguments, expects interface
|
74
77
|
def has_many(children_name, args)
|
75
|
-
|
78
|
+
has_many_relationships[children_name] = args
|
76
79
|
end
|
77
80
|
|
78
81
|
# @return [Hash] relationships for the composite
|
79
82
|
def has_many_relationships
|
80
|
-
@has_many_relationships ||=
|
83
|
+
@has_many_relationships ||= {}
|
81
84
|
end
|
82
85
|
|
83
86
|
# @param child_name [Symbol] name of key
|
84
87
|
# @param args [Hash] arguments
|
85
88
|
def has_one(child_name, args)
|
86
|
-
|
89
|
+
has_one_relationships[child_name] = args
|
87
90
|
end
|
88
91
|
|
89
92
|
# @return [Hash] hash of relationships
|
90
93
|
def has_one_relationships
|
91
|
-
@has_one_relationships ||=
|
94
|
+
@has_one_relationships ||= {}
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
95
|
-
end
|
98
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module AutomationObject
|
2
|
-
#Hooks for composites
|
3
|
+
# Hooks for composites
|
3
4
|
module CompositeHook
|
4
5
|
def before_create_run
|
5
|
-
self.class.before_create_hooks.each
|
6
|
-
|
7
|
-
|
6
|
+
self.class.before_create_hooks.each do |before_create_hook|
|
7
|
+
send(before_create_hook)
|
8
|
+
end
|
8
9
|
end
|
9
10
|
|
10
11
|
def after_create_run
|
11
|
-
self.class.after_create_hooks.each
|
12
|
-
|
13
|
-
|
12
|
+
self.class.after_create_hooks.each do |after_create_hook|
|
13
|
+
send(after_create_hook)
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
# @param base [Class] class to extend when included
|
@@ -18,29 +19,29 @@ module AutomationObject
|
|
18
19
|
base.extend(ClassMethods)
|
19
20
|
end
|
20
21
|
|
21
|
-
#Class level methods
|
22
|
+
# Class level methods
|
22
23
|
module ClassMethods
|
23
24
|
# @param instance_method [Symbol] method to call
|
24
25
|
def after_create(instance_method)
|
25
|
-
|
26
|
+
after_create_hooks.push(instance_method)
|
26
27
|
end
|
27
28
|
|
28
29
|
# @return [Array<Symbol>] list of methods to call
|
29
30
|
def after_create_hooks
|
30
|
-
@after_create_hooks = [] unless @after_create_hooks
|
31
|
-
|
31
|
+
@after_create_hooks = [] unless defined? @after_create_hooks
|
32
|
+
@after_create_hooks
|
32
33
|
end
|
33
34
|
|
34
35
|
# @param instance_method [Symbol] method to call
|
35
36
|
def before_create(instance_method)
|
36
|
-
|
37
|
+
before_create_hooks.push(instance_method)
|
37
38
|
end
|
38
39
|
|
39
40
|
# @return [Array<Symbol>] list of methods to call
|
40
41
|
def before_create_hooks
|
41
|
-
@before_create_hooks = [] unless @before_create_hooks
|
42
|
-
|
42
|
+
@before_create_hooks = [] unless defined? @before_create_hooks
|
43
|
+
@before_create_hooks
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
46
|
-
end
|
47
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Extend file class
|
3
|
+
# Collect files in directory recursively and return Array
|
4
|
+
class File
|
5
|
+
class << self
|
4
6
|
# @param path [String] specified directory path for getting files underneath
|
5
7
|
# @returns [Array] list of file paths that exist recursively underneath a directory
|
6
8
|
def collect_files(path)
|
7
|
-
unless File.
|
8
|
-
raise "Expecting path to exist, got #{path}"
|
9
|
-
end
|
9
|
+
raise "Expecting path to exist, got #{path}" unless File.exist?(path)
|
10
10
|
|
11
11
|
if File.directory?(path)
|
12
|
-
@file_array =
|
13
|
-
|
12
|
+
@file_array = []
|
13
|
+
recursive_collection(path)
|
14
14
|
else
|
15
15
|
@file_array = [path]
|
16
16
|
end
|
@@ -24,15 +24,15 @@ module AutomationObject::BluePrint
|
|
24
24
|
# @param path [String] specified directory path for getting files underneath
|
25
25
|
def recursive_collection(path)
|
26
26
|
Dir.foreach(path) do |item|
|
27
|
-
next if item == '.'
|
27
|
+
next if item == '.' || item == '..'
|
28
28
|
|
29
|
-
file_path = File.join(path,
|
29
|
+
file_path = File.join(path, item.to_s)
|
30
30
|
if File.directory?(file_path)
|
31
|
-
|
31
|
+
recursive_collection(file_path)
|
32
32
|
else
|
33
33
|
@file_array.push(file_path)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
|
-
#
|
2
|
-
class
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Hash class method additions
|
3
|
+
class Hash
|
3
4
|
def deep_merge(second)
|
4
|
-
merger = proc { |
|
5
|
-
|
5
|
+
merger = proc { |_key, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2 }
|
6
|
+
merge(second, &merger)
|
6
7
|
end
|
7
8
|
|
8
9
|
def symbolize_keys_deep!(h = self)
|
@@ -12,4 +13,4 @@ class ::Hash
|
|
12
13
|
symbolize_keys_deep! h[ks] if h[ks].is_a?(Hash)
|
13
14
|
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
@@ -1,28 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module AutomationObject
|
2
|
-
#Helper module for adding attributes/alias to classes dynamically
|
3
|
-
#Reflection/MetaProgramming
|
4
|
-
module
|
3
|
+
# Helper module for adding attributes/alias to classes dynamically
|
4
|
+
# Reflection/MetaProgramming
|
5
|
+
module Reflection
|
5
6
|
# @param name [String, Symbol] name of attribute to add
|
6
7
|
# @param value [Object] value of attribute
|
7
8
|
def add_attribute(name, value)
|
8
9
|
name = name.to_s
|
9
10
|
alias_name = name + '?' if name.gsub!(/\?$/, '')
|
10
11
|
|
11
|
-
self.class.send(:attr_accessor, name)
|
12
|
+
self.class.send(:attr_accessor, name) unless self.class.method_defined? name
|
12
13
|
instance_variable_set("@#{name}", value)
|
13
14
|
|
14
|
-
|
15
|
+
add_alias(alias_name, name) if alias_name
|
15
16
|
end
|
16
17
|
|
17
18
|
# @param alias_name [Symbol, String] name of alias to add
|
18
19
|
# @param attribute_name [Symbol, String] attribute to link to
|
19
20
|
def add_alias(alias_name, attribute_name)
|
20
|
-
singleton_class = class << self
|
21
|
-
self
|
21
|
+
singleton_class = class << self
|
22
|
+
self
|
22
23
|
end
|
23
24
|
singleton_class.send(:define_method, alias_name) do
|
24
25
|
instance_variable_get("@#{attribute_name}")
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
@@ -1,27 +1,37 @@
|
|
1
|
-
#
|
2
|
-
class
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# String class method additions
|
3
|
+
class String
|
4
|
+
# Test whether a string is a valid url or not
|
5
|
+
# @return [Boolean]
|
3
6
|
def valid_url?
|
4
7
|
uri = URI.parse(self)
|
5
|
-
if uri.
|
6
|
-
|
7
|
-
return true
|
8
|
-
else
|
9
|
-
return false
|
10
|
-
end
|
11
|
-
else
|
12
|
-
return false
|
13
|
-
end
|
8
|
+
return true if uri.is_a?(URI::HTTP)
|
9
|
+
return !(self =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix).nil?
|
14
10
|
rescue URI::InvalidURIError
|
15
11
|
return false
|
16
12
|
end
|
17
13
|
|
18
14
|
def join_url(url)
|
19
|
-
full_url =
|
20
|
-
|
15
|
+
full_url = chomp('/') + url.reverse.chomp('/').reverse
|
16
|
+
full_url
|
21
17
|
end
|
22
18
|
|
19
|
+
# Convert self to pascal case
|
23
20
|
def pascalize
|
24
21
|
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
25
|
-
|
22
|
+
split('_').map(&:capitalize).join
|
26
23
|
end
|
27
|
-
|
24
|
+
|
25
|
+
# Convert string to underscore
|
26
|
+
# @return [String] underscored self string
|
27
|
+
def to_underscore!
|
28
|
+
gsub!(/(.)([A-Z])/, '\1_\2')
|
29
|
+
downcase!
|
30
|
+
end
|
31
|
+
|
32
|
+
# Convert string to underscore
|
33
|
+
# @return [String] underscored string
|
34
|
+
def to_underscore
|
35
|
+
dup.tap(&:to_underscore!)
|
36
|
+
end
|
37
|
+
end
|