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
@@ -1,30 +1,31 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Require parent class
|
2
3
|
require_relative 'composite'
|
3
4
|
|
4
5
|
module AutomationObject
|
5
6
|
module BluePrint
|
6
7
|
module HashAdapter
|
7
|
-
#Custom method composite
|
8
|
+
# Custom method composite
|
8
9
|
class CustomMethod < Composite
|
9
|
-
#Validations
|
10
|
+
# Validations
|
10
11
|
validates :element_method, instance_of: [String, Symbol], presence_of: true
|
11
12
|
validates :evaluate, instance_of: [String], presence_of: true
|
12
13
|
|
13
14
|
def element_method
|
14
|
-
element_method =
|
15
|
+
element_method = hash[:element_method]
|
15
16
|
|
16
17
|
case element_method
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
when Symbol, String
|
19
|
+
return element_method.to_sym
|
20
|
+
else
|
21
|
+
return nil
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def evaluate
|
25
|
-
|
26
|
+
hash[:evaluate] ||= nil
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
|
-
end
|
31
|
+
end
|
@@ -1,34 +1,35 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Require parent class
|
2
3
|
require_relative 'composite'
|
3
4
|
|
4
|
-
#Require child classes
|
5
|
+
# Require child classes
|
5
6
|
require_relative 'hook'
|
6
7
|
require_relative 'custom_method'
|
7
8
|
|
8
|
-
#Require helpers
|
9
|
+
# Require helpers
|
9
10
|
require_relative 'helpers/element_helper'
|
10
11
|
|
11
12
|
module AutomationObject
|
12
13
|
module BluePrint
|
13
14
|
module HashAdapter
|
14
|
-
#Element composite
|
15
|
+
# Element composite
|
15
16
|
class Element < Composite
|
16
17
|
include ElementHelper
|
17
18
|
|
18
19
|
before_create :method_hooks
|
19
20
|
|
20
|
-
#Relationships
|
21
|
+
# Relationships
|
21
22
|
has_one :load, interface: Hook
|
22
23
|
has_many :custom_methods, interface: CustomMethod
|
23
24
|
|
24
|
-
#Validations
|
25
|
+
# Validations
|
25
26
|
validates :load, instance_of: Hash
|
26
27
|
validates :custom_methods, instance_of: Hash
|
27
28
|
|
28
29
|
validates :in_iframe, instance_of: String, element_presence_of: true
|
29
|
-
validates :css, instance_of: String, presence_of: {:
|
30
|
-
validates :xpath, instance_of: String, presence_of: {:
|
30
|
+
validates :css, instance_of: String, presence_of: { unless_presence_of: :xpath }
|
31
|
+
validates :xpath, instance_of: String, presence_of: { unless_presence_of: :css }
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
34
|
-
end
|
35
|
+
end
|
@@ -1,36 +1,37 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Require parent class
|
2
3
|
require_relative 'composite'
|
3
4
|
|
4
|
-
#Require child classes
|
5
|
+
# Require child classes
|
5
6
|
require_relative 'hook'
|
6
7
|
require_relative 'custom_method'
|
7
8
|
|
8
|
-
#Require helpers
|
9
|
+
# Require helpers
|
9
10
|
require_relative 'helpers/element_helper'
|
10
11
|
require_relative 'helpers/multiple_elements_helper'
|
11
12
|
|
12
13
|
module AutomationObject
|
13
14
|
module BluePrint
|
14
15
|
module HashAdapter
|
15
|
-
#Element array composite
|
16
|
+
# Element array composite
|
16
17
|
class ElementArray < Composite
|
17
18
|
include ElementHelper
|
18
19
|
include MultipleElementsHelper
|
19
20
|
|
20
21
|
before_create :method_hooks
|
21
22
|
|
22
|
-
#Relationships
|
23
|
+
# Relationships
|
23
24
|
has_one :load, interface: Hook
|
24
25
|
has_many :custom_methods, interface: CustomMethod
|
25
26
|
|
26
|
-
#Validations
|
27
|
+
# Validations
|
27
28
|
validates :load, instance_of: Hash
|
28
29
|
validates :custom_range, instance_of: [Hash, String]
|
29
30
|
validates :in_iframe, instance_of: String, element_presence_of: true
|
30
31
|
validates :custom_methods, instance_of: Hash
|
31
|
-
validates :css, instance_of: String, presence_of: {:
|
32
|
-
validates :xpath, instance_of: String, presence_of: {:
|
32
|
+
validates :css, instance_of: String, presence_of: { unless_presence_of: :xpath }
|
33
|
+
validates :xpath, instance_of: String, presence_of: { unless_presence_of: :css }
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
36
|
-
end
|
37
|
+
end
|
@@ -1,43 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Require parent class
|
2
3
|
require_relative 'composite'
|
3
4
|
|
4
|
-
#Require child classes
|
5
|
+
# Require child classes
|
5
6
|
require_relative 'hook'
|
6
7
|
require_relative 'custom_method'
|
7
8
|
|
8
|
-
#Require helpers
|
9
|
+
# Require helpers
|
9
10
|
require_relative 'helpers/element_helper'
|
10
11
|
require_relative 'helpers/multiple_elements_helper'
|
11
12
|
|
12
13
|
module AutomationObject
|
13
14
|
module BluePrint
|
14
15
|
module HashAdapter
|
15
|
-
#Element hash composite
|
16
|
+
# Element hash composite
|
16
17
|
class ElementHash < Composite
|
17
18
|
include ElementHelper
|
18
19
|
include MultipleElementsHelper
|
19
20
|
|
20
21
|
before_create :method_hooks
|
21
22
|
|
22
|
-
#Relationships
|
23
|
+
# Relationships
|
23
24
|
has_one :load, interface: Hook
|
24
25
|
has_many :custom_methods, interface: CustomMethod
|
25
26
|
|
26
|
-
#Validations
|
27
|
+
# Validations
|
27
28
|
validates :load, instance_of: Hash
|
28
29
|
|
29
30
|
validates :define_elements_by, instance_of: [String, Symbol], presence_of: true
|
30
31
|
validates :custom_range, instance_of: [Hash, String]
|
31
32
|
validates :in_iframe, instance_of: String, element_presence_of: true
|
32
33
|
validates :custom_methods, instance_of: Hash
|
33
|
-
validates :css, instance_of: String, presence_of: {:
|
34
|
-
validates :xpath, instance_of: String, presence_of: {:
|
34
|
+
validates :css, instance_of: String, presence_of: { unless_presence_of: :xpath }
|
35
|
+
validates :xpath, instance_of: String, presence_of: { unless_presence_of: :css }
|
35
36
|
|
36
37
|
# @return [Symbol] element method to define element keys by
|
37
38
|
def define_elements_by
|
38
|
-
|
39
|
+
hash[:define_elements_by].to_sym
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
43
|
-
end
|
44
|
+
end
|
@@ -1,59 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module AutomationObject
|
2
3
|
module BluePrint
|
3
4
|
module HashAdapter
|
4
|
-
#Helper module for Element composite classes
|
5
|
+
# Helper module for Element composite classes
|
5
6
|
module ElementHelper
|
6
7
|
# @return [Array<Symbol, String>, nil] params as an array for driver find_element args
|
7
8
|
def selector_params
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
[:css, self.hash[:css]]
|
13
|
-
else
|
14
|
-
nil
|
9
|
+
if hash[:xpath].is_a?(String)
|
10
|
+
[:xpath, hash[:xpath]]
|
11
|
+
elsif hash[:css].is_a?(String)
|
12
|
+
[:css, hash[:css]]
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
16
|
# @return [Symbol, nil] element name of iframe element is in or nil if not
|
19
17
|
def in_iframe
|
20
|
-
case
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
nil
|
18
|
+
case hash[:in_iframe]
|
19
|
+
when Symbol, String
|
20
|
+
hash[:in_iframe].to_sym
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
24
|
# @return [Boolean] whether or not element is in iframe
|
29
25
|
def in_iframe?
|
30
|
-
|
26
|
+
in_iframe ? true : false
|
31
27
|
end
|
32
28
|
|
33
29
|
def method_hook?(name)
|
34
|
-
|
30
|
+
method_hooks.key?(name)
|
35
31
|
end
|
36
32
|
|
37
33
|
# @return [Hash<Hook>] array of Hook that are defined under the element
|
38
34
|
def method_hooks
|
39
|
-
return @method_hooks if @method_hooks
|
35
|
+
return @method_hooks if defined? @method_hooks
|
40
36
|
|
41
37
|
children = {}
|
42
|
-
|
43
|
-
#Skip possible keys that elements can have
|
44
|
-
#Otherwise should be a method hook
|
38
|
+
hash.each do |key, value|
|
39
|
+
# Skip possible keys that elements can have
|
40
|
+
# Otherwise should be a method hook
|
45
41
|
next if [:load, :custom_methods, :in_iframe, :css, :xpath, :define_elements_by, :custom_range].include?(key)
|
46
42
|
children[key] = value
|
47
|
-
|
43
|
+
end
|
48
44
|
|
49
|
-
@method_hooks =
|
50
|
-
|
51
|
-
|
45
|
+
@method_hooks = create_hash_children(children,
|
46
|
+
interface: Hook,
|
47
|
+
location: location + '[hook]')
|
52
48
|
|
53
|
-
|
49
|
+
@method_hooks
|
54
50
|
end
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
59
|
-
|
@@ -1,35 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module AutomationObject
|
2
3
|
module BluePrint
|
3
4
|
module HashAdapter
|
4
|
-
#Helper module for multiple element composite classes
|
5
|
+
# Helper module for multiple element composite classes
|
5
6
|
module MultipleElementsHelper
|
6
7
|
# @return [Range, nil] gives range for limiting multiple elements or nil
|
7
8
|
def custom_range
|
8
|
-
custom_range =
|
9
|
+
custom_range = hash[:custom_range]
|
9
10
|
|
10
11
|
case custom_range
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
when String
|
13
|
+
integer_array = custom_range.split('..').map { |number| Integer(number) }
|
14
|
+
return integer_array[0]..integer_array[1]
|
15
|
+
when Hash
|
16
|
+
return custom_range[:start].to_i..custom_range[:end].to_i
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
+
nil
|
19
20
|
end
|
20
21
|
|
21
22
|
# @return [Symbol, nil] gives element method to remove duplicates on or nil
|
22
23
|
def remove_duplicates
|
23
|
-
remove_duplicates =
|
24
|
+
remove_duplicates = hash[:remove_duplicates]
|
24
25
|
|
25
26
|
case remove_duplicates
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
when Symbol, String
|
28
|
+
return remove_duplicates.to_sym
|
29
|
+
else
|
30
|
+
return nil
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
35
|
-
end
|
36
|
+
end
|
@@ -1,26 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module AutomationObject
|
2
3
|
module BluePrint
|
3
4
|
module HashAdapter
|
4
|
-
#ValidatorError exception class
|
5
|
-
#Allows for multiple errors at one time to allow for better debugging
|
6
|
-
class ValidationError <
|
5
|
+
# ValidatorError exception class
|
6
|
+
# Allows for multiple errors at one time to allow for better debugging
|
7
|
+
class ValidationError < RuntimeError
|
7
8
|
attr_accessor :errors
|
8
9
|
|
9
10
|
# @param errors [Array, String] pass validation error(s) in, class can handle singular or multiple
|
10
11
|
def initialize(errors)
|
11
|
-
@errors =
|
12
|
+
@errors = errors.is_a?(Array) ? errors : [errors]
|
12
13
|
end
|
13
14
|
|
14
15
|
# @return [String] returns full error message
|
15
16
|
def message
|
16
17
|
message = "\nBluePrint::HashAdapter composite validation failed for the following errors:\n"
|
17
|
-
@errors.each
|
18
|
+
@errors.each do |error|
|
18
19
|
message << " - #{error}\n"
|
19
|
-
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
message + "\n"
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
26
|
-
end
|
27
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Require all the validators
|
2
3
|
require_relative 'validators/validate_instance_of'
|
3
4
|
require_relative 'validators/validate_allowed_keys'
|
4
5
|
require_relative 'validators/validate_screen_presence_of'
|
@@ -12,14 +13,16 @@ require_relative '../../../helpers/string'
|
|
12
13
|
module AutomationObject
|
13
14
|
module BluePrint
|
14
15
|
module HashAdapter
|
15
|
-
#Validation helper for the composite structure, will allow Rails style validations on the composite
|
16
|
+
# Validation helper for the composite structure, will allow Rails style validations on the composite
|
16
17
|
module ValidationHelper
|
17
18
|
attr_accessor :errors
|
18
19
|
|
20
|
+
# Remove getter to solve stupid Ruby warning
|
21
|
+
undef :errors if method_defined? :errors
|
19
22
|
# Give errors a default empty Array
|
20
23
|
# @return [Array<String>] errors messages
|
21
24
|
def errors
|
22
|
-
@errors ||=
|
25
|
+
@errors ||= []
|
23
26
|
end
|
24
27
|
|
25
28
|
# Give errors a default empty Array
|
@@ -33,27 +36,25 @@ module AutomationObject
|
|
33
36
|
def valid?
|
34
37
|
return true if self.class.skip_validations
|
35
38
|
|
36
|
-
|
37
|
-
#ap self.class.name
|
39
|
+
# ap self.class
|
40
|
+
# ap self.class.name
|
38
41
|
self.class.validations.collect do |validation|
|
39
|
-
|
42
|
+
# ap validation.class.name
|
40
43
|
end
|
41
44
|
|
42
45
|
self.class.validations.collect do |validation|
|
43
46
|
validation.validate(self)
|
44
|
-
unless validation.valid?
|
45
|
-
self.add_errors(validation.error_messages)
|
46
|
-
end
|
47
|
+
add_errors(validation.error_messages) unless validation.valid?
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
self.errors.empty?
|
50
51
|
end
|
51
52
|
|
52
53
|
def self.included(base)
|
53
54
|
base.extend(ClassMethods)
|
54
55
|
end
|
55
56
|
|
56
|
-
#Class level methods
|
57
|
+
# Class level methods
|
57
58
|
module ClassMethods
|
58
59
|
def skip_validations=(boolean)
|
59
60
|
@skip_validations = boolean
|
@@ -67,33 +68,27 @@ module AutomationObject
|
|
67
68
|
# @param args [Hash] arguments for validation
|
68
69
|
# @return [nil]
|
69
70
|
def validates(key, args = {})
|
70
|
-
|
71
|
-
# ap self.class.name
|
72
|
-
# ap key
|
73
|
-
# ap args
|
74
|
-
|
75
|
-
|
76
|
-
args.each { |validator_name, validation_args|
|
71
|
+
args.each do |validator_name, validation_args|
|
77
72
|
validator_name = 'Validate' + validator_name.to_s.pascalize
|
78
73
|
validator = Validators.const_get(validator_name)
|
79
74
|
|
80
|
-
|
81
|
-
|
75
|
+
validations.push(validator.new(key: key, args: validation_args))
|
76
|
+
end
|
82
77
|
end
|
83
78
|
|
84
79
|
# @param args [Hash] arguments for validation
|
85
80
|
# @return [nil]
|
86
81
|
def validates_keys(args = {})
|
87
|
-
|
82
|
+
validations.push(Validators::ValidateAllowedKeys.new(args))
|
88
83
|
end
|
89
84
|
|
90
85
|
# @return [Array] list of Validators, default to empty list
|
91
86
|
def validations
|
92
|
-
@validations = [] unless @validations
|
93
|
-
|
87
|
+
@validations = [] unless defined? @validations
|
88
|
+
@validations
|
94
89
|
end
|
95
90
|
end
|
96
91
|
end
|
97
92
|
end
|
98
93
|
end
|
99
|
-
end
|
94
|
+
end
|