automation_object 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/lib/automation_object.rb +22 -11
  3. data/lib/automation_object/blue_print.rb +13 -12
  4. data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +9 -8
  5. data/lib/automation_object/blue_print/composite/base.rb +5 -4
  6. data/lib/automation_object/blue_print/composite/custom_method.rb +8 -7
  7. data/lib/automation_object/blue_print/composite/element.rb +6 -5
  8. data/lib/automation_object/blue_print/composite/element_array.rb +6 -5
  9. data/lib/automation_object/blue_print/composite/element_hash.rb +7 -6
  10. data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +7 -7
  11. data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +5 -4
  12. data/lib/automation_object/blue_print/composite/hook.rb +9 -11
  13. data/lib/automation_object/blue_print/composite/hook_action.rb +25 -24
  14. data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +14 -13
  15. data/lib/automation_object/blue_print/composite/modal.rb +11 -21
  16. data/lib/automation_object/blue_print/composite/screen.rb +22 -16
  17. data/lib/automation_object/blue_print/composite/top.rb +13 -12
  18. data/lib/automation_object/blue_print/composite/view.rb +27 -16
  19. data/lib/automation_object/blue_print/hash_adapter.rb +15 -11
  20. data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +12 -11
  21. data/lib/automation_object/blue_print/hash_adapter/composite.rb +28 -25
  22. data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +11 -10
  23. data/lib/automation_object/blue_print/hash_adapter/element.rb +10 -9
  24. data/lib/automation_object/blue_print/hash_adapter/element_array.rb +10 -9
  25. data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +11 -10
  26. data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +20 -25
  27. data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +15 -14
  28. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +9 -8
  29. data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +19 -24
  30. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +8 -5
  31. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +7 -8
  32. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +28 -23
  33. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +12 -13
  34. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +27 -23
  35. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +9 -8
  36. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +27 -23
  37. data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +25 -21
  38. data/lib/automation_object/blue_print/hash_adapter/hook.rb +14 -11
  39. data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +45 -47
  40. data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +24 -28
  41. data/lib/automation_object/blue_print/hash_adapter/modal.rb +14 -13
  42. data/lib/automation_object/blue_print/hash_adapter/screen.rb +23 -22
  43. data/lib/automation_object/blue_print/hash_adapter/top.rb +16 -15
  44. data/lib/automation_object/blue_print/hash_adapter/view.rb +58 -4
  45. data/lib/automation_object/blue_print/yaml_adapter.rb +33 -34
  46. data/lib/automation_object/driver.rb +15 -13
  47. data/lib/automation_object/driver/appium_adapter/driver.rb +47 -46
  48. data/lib/automation_object/driver/appium_adapter/element.rb +29 -96
  49. data/lib/automation_object/driver/base.rb +4 -2
  50. data/lib/automation_object/driver/common_selenium/driver.rb +60 -0
  51. data/lib/automation_object/driver/common_selenium/element.rb +107 -0
  52. data/lib/automation_object/driver/common_selenium/element_geometry.rb +86 -0
  53. data/lib/automation_object/driver/driver.rb +60 -30
  54. data/lib/automation_object/driver/element.rb +70 -15
  55. data/lib/automation_object/driver/nokogiri_adapter/driver.rb +88 -34
  56. data/lib/automation_object/driver/nokogiri_adapter/element.rb +94 -16
  57. data/lib/automation_object/driver/nokogiri_adapter/error.rb +29 -8
  58. data/lib/automation_object/driver/nokogiri_adapter/{backup/form.rb → form.rb} +19 -6
  59. data/lib/automation_object/driver/nokogiri_adapter/request.rb +17 -0
  60. data/lib/automation_object/driver/nokogiri_adapter/session.rb +94 -0
  61. data/lib/automation_object/driver/nokogiri_adapter/window.rb +86 -0
  62. data/lib/automation_object/driver/selenium_adapter/driver.rb +36 -45
  63. data/lib/automation_object/driver/selenium_adapter/element.rb +15 -85
  64. data/lib/automation_object/dsl.rb +11 -28
  65. data/lib/automation_object/dsl/_base.rb +70 -0
  66. data/lib/automation_object/dsl/_proxy.rb +24 -0
  67. data/lib/automation_object/dsl/element.rb +34 -0
  68. data/lib/automation_object/dsl/element_array.rb +34 -0
  69. data/lib/automation_object/dsl/element_hash.rb +34 -0
  70. data/lib/automation_object/dsl/modal.rb +43 -0
  71. data/lib/automation_object/dsl/screen.rb +45 -0
  72. data/lib/automation_object/dsl/top.rb +25 -0
  73. data/lib/automation_object/framework.rb +28 -38
  74. data/lib/automation_object/helpers/composite.rb +30 -27
  75. data/lib/automation_object/helpers/composite_hook.rb +16 -15
  76. data/lib/automation_object/{blue_print/helpers/file_helper.rb → helpers/file.rb} +12 -12
  77. data/lib/automation_object/helpers/hash.rb +6 -5
  78. data/lib/automation_object/helpers/kernel.rb +11 -0
  79. data/lib/automation_object/helpers/{reflection_helper.rb → reflection.rb} +9 -8
  80. data/lib/automation_object/helpers/string.rb +25 -15
  81. data/lib/automation_object/{proxies → proxy}/mutex_proxy.rb +18 -21
  82. data/lib/automation_object/proxy/proxy.rb +23 -0
  83. data/lib/automation_object/proxy/throttle_proxy.rb +52 -0
  84. data/lib/automation_object/state.rb +11 -29
  85. data/lib/automation_object/state/{blue_print_adapter/composite.rb → composite/_base.rb} +35 -25
  86. data/lib/automation_object/state/{blue_print_adapter/helpers/element_helper.rb → composite/_common_element.rb} +11 -11
  87. data/lib/automation_object/state/composite/element.rb +22 -0
  88. data/lib/automation_object/state/composite/element_array.rb +27 -0
  89. data/lib/automation_object/state/composite/element_hash.rb +33 -0
  90. data/lib/automation_object/state/composite/element_proxy.rb +33 -0
  91. data/lib/automation_object/state/composite/helpers/window.rb +61 -0
  92. data/lib/automation_object/state/composite/helpers/window_manager.rb +60 -0
  93. data/lib/automation_object/state/composite/hook.rb +56 -0
  94. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_action.rb +10 -8
  95. data/lib/automation_object/state/composite/hook_actions/action_loop.rb +36 -0
  96. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_screen.rb +7 -5
  97. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/change_to_previous_screen.rb +7 -5
  98. data/lib/automation_object/state/composite/hook_actions/close_modal.rb +29 -0
  99. data/lib/automation_object/state/composite/hook_actions/close_screen.rb +19 -0
  100. data/lib/automation_object/state/composite/hook_actions/element_requirement.rb +32 -0
  101. data/lib/automation_object/state/composite/hook_actions/new_screen.rb +35 -0
  102. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/possible_screen_changes.rb +8 -7
  103. data/lib/automation_object/state/composite/hook_actions/reset_screen.rb +14 -0
  104. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/show_modal.rb +7 -5
  105. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/sleep.rb +4 -2
  106. data/lib/automation_object/state/{blue_print_adapter → composite}/hook_actions/wait_for_elements.rb +7 -5
  107. data/lib/automation_object/state/composite/modal.rb +45 -0
  108. data/lib/automation_object/state/composite/screen.rb +58 -0
  109. data/lib/automation_object/state/composite/top.rb +51 -0
  110. data/lib/automation_object/state/error.rb +45 -6
  111. data/lib/automation_object/state/session.rb +25 -23
  112. data/lib/automation_object/step_definitions.rb +5 -3
  113. data/lib/automation_object/step_definitions/element.rb +77 -0
  114. data/lib/automation_object/step_definitions/element_array.rb +135 -0
  115. data/lib/automation_object/step_definitions/element_hash.rb +126 -0
  116. data/lib/automation_object/step_definitions/screen.rb +62 -0
  117. data/lib/automation_object/step_definitions/{cache.rb → support/cache.rb} +8 -6
  118. data/lib/automation_object/step_definitions/support/element_array.rb +40 -0
  119. data/lib/automation_object/step_definitions/support/element_hash.rb +41 -0
  120. data/lib/automation_object/step_definitions/{parse.rb → support/parse.rb} +8 -6
  121. data/lib/automation_object/version.rb +2 -1
  122. metadata +203 -103
  123. data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +0 -41
  124. data/lib/automation_object/driver/helpers/selenium_element_helper.rb +0 -138
  125. data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +0 -83
  126. data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +0 -66
  127. data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +0 -52
  128. data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +0 -115
  129. data/lib/automation_object/dsl/blue_print_adapter.rb +0 -16
  130. data/lib/automation_object/dsl/blue_print_adapter/composite.rb +0 -54
  131. data/lib/automation_object/dsl/blue_print_adapter/element.rb +0 -14
  132. data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +0 -14
  133. data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +0 -14
  134. data/lib/automation_object/dsl/blue_print_adapter/modal.rb +0 -23
  135. data/lib/automation_object/dsl/blue_print_adapter/screen.rb +0 -26
  136. data/lib/automation_object/dsl/blue_print_adapter/top.rb +0 -19
  137. data/lib/automation_object/dsl/models.rb +0 -18
  138. data/lib/automation_object/dsl/proxies/element.rb +0 -16
  139. data/lib/automation_object/dsl/proxies/element_array.rb +0 -16
  140. data/lib/automation_object/dsl/proxies/element_hash.rb +0 -16
  141. data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +0 -74
  142. data/lib/automation_object/dsl/proxies/modal.rb +0 -17
  143. data/lib/automation_object/dsl/proxies/screen.rb +0 -17
  144. data/lib/automation_object/dsl/proxies/top.rb +0 -17
  145. data/lib/automation_object/proxies/proxy.rb +0 -20
  146. data/lib/automation_object/proxies/throttle_proxy.rb +0 -57
  147. data/lib/automation_object/state/blue_print_adapter.rb +0 -16
  148. data/lib/automation_object/state/blue_print_adapter/element.rb +0 -20
  149. data/lib/automation_object/state/blue_print_adapter/element_array.rb +0 -25
  150. data/lib/automation_object/state/blue_print_adapter/element_hash.rb +0 -31
  151. data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +0 -28
  152. data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +0 -137
  153. data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +0 -39
  154. data/lib/automation_object/state/blue_print_adapter/hook.rb +0 -56
  155. data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +0 -35
  156. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +0 -31
  157. data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +0 -19
  158. data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +0 -34
  159. data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +0 -37
  160. data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +0 -18
  161. data/lib/automation_object/state/blue_print_adapter/modal.rb +0 -26
  162. data/lib/automation_object/state/blue_print_adapter/screen.rb +0 -32
  163. data/lib/automation_object/state/blue_print_adapter/top.rb +0 -45
  164. data/lib/automation_object/step_definitions/action.rb +0 -21
  165. data/lib/automation_object/step_definitions/element/actions.rb +0 -87
  166. data/lib/automation_object/step_definitions/element/regex.rb +0 -24
  167. data/lib/automation_object/step_definitions/element/steps.rb +0 -67
@@ -1,23 +1,26 @@
1
+ # frozen_string_literal: true
1
2
  module AutomationObject
2
3
  module BluePrint
3
4
  module HashAdapter
4
5
  module Validators
5
- #Super-class for validators, contains base functionality
6
- #Sub-classes must implement validate for the composite
6
+ # Super-class for validators, contains base functionality
7
+ # Sub-classes must implement validate for the composite
7
8
  class Validate
8
9
  attr_accessor :error_messages
9
10
 
11
+ # Remove getter to solve stupid Ruby warning
12
+ undef :error_messages if method_defined? :error_messages
10
13
  # @return [Array<String>] array of error messages, default empty array
11
14
  def error_messages
12
- @error_messages ||= Array.new
15
+ @error_messages ||= []
13
16
  end
14
17
 
15
18
  # @return [Boolean] whether or not validation passed or failed
16
19
  def valid?
17
- return (self.error_messages.length == 0) ? true : false
20
+ error_messages.length.zero? ? true : false
18
21
  end
19
22
  end
20
23
  end
21
24
  end
22
25
  end
23
- end
26
+ end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests the composite hash for bad keys
8
+ # Validator that tests the composite hash for bad keys
8
9
  class ValidateAllowedKeys < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
@@ -15,17 +16,15 @@ module AutomationObject
15
16
  # @param composite_object [Object] Composite object to be tested.
16
17
  # @return [nil] no return on exceptions on failure
17
18
  def validate(composite_object)
18
- #Get the hash from the composite object
19
+ # Get the hash from the composite object
19
20
  target_hash = composite_object.hash
20
21
 
21
- target_hash.each_key { |key|
22
- unless @allowed_keys.include?(key)
23
- self.error_messages.push("Invalid Key: #{key}, at: #{composite_object.location}. Allowed keys: #{@allowed_keys}.")
24
- end
25
- }
22
+ target_hash.each_key do |key|
23
+ error_messages.push("Invalid Key: #{key}, at: #{composite_object.location}. Allowed keys: #{@allowed_keys}.") unless @allowed_keys.include?(key)
24
+ end
26
25
  end
27
26
  end
28
27
  end
29
28
  end
30
29
  end
31
- end
30
+ end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests that a element is defined when it is called elsewhere through a hook
8
+ # Validator that tests that a element is defined when it is called elsewhere through a hook
8
9
  class ValidateElementPresenceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
@@ -15,41 +16,45 @@ module AutomationObject
15
16
  # @param composite_object [Object] Composite object to be tested.
16
17
  # @return [nil] no return on exceptions on failure
17
18
  def validate(composite_object)
18
- #Get the hash value from the composite object
19
+ # Get the hash value from the composite object
19
20
  target_value = composite_object.hash[@key]
20
21
 
21
22
  return unless target_value
22
23
 
23
- target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
24
+ target_values = target_value.is_a?(Array) ? target_value : [target_value]
25
+ valid_elements = find_elements(composite_object)
24
26
 
25
- valid_elements = self.find_elements(composite_object)
26
-
27
- target_values.each { |element|
28
- element = element.to_sym
29
- next if valid_elements.include?(element)
30
-
31
- error_message = "Invalid Element: #{element}, at: #{composite_object.location}[#{@key}]."
32
- error_message << " Valid Elements(s): #{valid_elements}"
33
- self.error_messages.push(error_message)
34
- }
27
+ populate_errors(target_values, valid_elements, composite_object)
35
28
  end
36
29
 
37
- #Traverses up a composite tree to find :elements in a hash
30
+ private
31
+
32
+ # Traverses up a composite tree to find :elements in a hash
38
33
  # @param composite_object [Object] composite object to traverse up
39
34
  # @return [Array<Symbol>] array of element names
40
35
  def find_elements(composite_object)
41
- #Using the hash instead of the method because lower nodes will get validated
42
- #before composite is finished building
43
- if composite_object.hash[:elements].is_a?(Hash)
44
- return composite_object.hash[:elements].keys #Should be Hash with element names as the keys
45
- elsif composite_object.parent
46
- return self.find_elements(composite_object.parent)
47
- end
36
+ # Using the hash instead of the method because lower nodes will get validated
37
+ # before composite is finished building
38
+ return composite_object.hash[:elements].keys if composite_object.hash[:elements].is_a?(Hash)
39
+
40
+ # Should be Hash with element names as the keys
41
+ return find_elements(composite_object.parent) if composite_object.parent
48
42
 
49
- return []
43
+ []
44
+ end
45
+
46
+ def populate_errors(target_values, valid_elements, composite_object)
47
+ target_values.each do |element|
48
+ element = element.to_sym
49
+ next if valid_elements.include?(element)
50
+
51
+ error_message = "Invalid Element: #{element}, at: #{composite_object.location}[#{@key}]."
52
+ error_message += " Valid Elements(s): #{valid_elements}"
53
+ error_messages.push(error_message)
54
+ end
50
55
  end
51
56
  end
52
57
  end
53
58
  end
54
59
  end
55
- end
60
+ end
@@ -1,39 +1,38 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests that a element is defined when it is called elsewhere through a hook
8
+ # Validator that tests that a element is defined when it is called elsewhere through a hook
8
9
  class ValidateInstanceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
11
12
  @key = args.fetch :key
12
- #Convert to array of instances for consistency
13
- @should_be_instances_of = (args.fetch(:args).is_a?(Array)) ? args.fetch(:args) : [args.fetch(:args)]
13
+ # Convert to array of instances for consistency
14
+ @should_be_instances_of = args.fetch(:args).is_a?(Array) ? args.fetch(:args) : [args.fetch(:args)]
14
15
  end
15
16
 
16
- # Validates the composite object and throws errors on failure
17
- # @param composite_object [Object] Composite object to be tested.
17
+ # Validates the composite object and adds errors on failure
18
+ # @param composite_object [AutomationObject::BluePrint::HashAdapter::Composite] composite
18
19
  # @return [nil] no return on exceptions on failure
19
20
  def validate(composite_object)
20
- #Get the hash value from the composite object
21
+ # Get the hash value from the composite object
21
22
  target_value = composite_object.hash[@key]
22
23
 
23
- #Skip empty or non-existent
24
+ # Skip empty or non-existent
24
25
  return unless target_value
25
26
 
26
- @should_be_instances_of.each { |should_be_instance_of|
27
- return if target_value.is_a?(should_be_instance_of)
28
- }
27
+ return if @should_be_instances_of.any? { |should_instance| target_value.is_a?(should_instance) }
29
28
 
30
29
  error_message = "Invalid Type: #{target_value.class}, at: #{composite_object.location}[#{@key}]."
31
- error_message << " Allowed Type(s): #{@should_be_instances_of}"
30
+ error_message += " Allowed Type(s): #{@should_be_instances_of}"
32
31
 
33
- self.error_messages.push(error_message)
32
+ error_messages.push(error_message)
34
33
  end
35
34
  end
36
35
  end
37
36
  end
38
37
  end
39
- end
38
+ end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests that a modal is defined when it is called elsewhere through a hook
8
+ # Validator that tests that a modal is defined when it is called elsewhere through a hook
8
9
  class ValidateModalPresenceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
@@ -15,40 +16,43 @@ module AutomationObject
15
16
  # @param composite_object [Object] Composite object to be tested.
16
17
  # @return [nil] no return on exceptions on failure
17
18
  def validate(composite_object)
18
- #Get the hash value from the composite object
19
+ # Get the hash value from the composite object
19
20
  target_value = composite_object.hash[@key]
20
- target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
21
+ target_values = target_value.is_a?(Array) ? target_value : [target_value]
21
22
 
22
23
  return unless target_value
23
24
 
24
- valid_modals = self.find_modals(composite_object)
25
-
26
- target_values.each { |modal|
27
- modal = modal.to_sym
28
- next if valid_modals.include?(modal)
29
-
30
- error_message = "Invalid Modal: #{modal}, at: #{composite_object.location}[#{@key}]."
31
- error_message << " Valid Modal(s): #{valid_modals}"
32
- self.error_messages.push(error_message)
33
- }
25
+ valid_modals = find_modals(composite_object)
26
+ populate_errors(target_values, valid_modals, composite_object)
34
27
  end
35
28
 
36
- #Traverses up a composite tree to find :modals in a hash
29
+ private
30
+
31
+ # Traverses up a composite tree to find :modals in a hash
37
32
  # @param composite_object [Object] composite object to traverse up
38
33
  # @return [Array<Symbol>] array of modal names
39
34
  def find_modals(composite_object)
40
- #Using the hash instead of the method because lower nodes will get validated
41
- #before composite is finished building
42
- if composite_object.hash[:modals].is_a?(Hash)
43
- return composite_object.hash[:modals].keys #Should be Hash with modal names as the keys
44
- elsif composite_object.parent
45
- return self.find_modals(composite_object.parent)
46
- end
35
+ # Using the hash instead of the method because lower nodes will get validated
36
+ # before composite is finished building
37
+ return composite_object.hash[:modals].keys if composite_object.hash[:modals].is_a?(Hash)
38
+
39
+ return find_modals(composite_object.parent) if composite_object.parent
47
40
 
48
- return []
41
+ []
42
+ end
43
+
44
+ def populate_errors(target_values, valid_modals, composite_object)
45
+ target_values.each do |modal|
46
+ modal = modal.to_sym
47
+ next if valid_modals.include?(modal)
48
+
49
+ error_message = "Invalid Modal: #{modal}, at: #{composite_object.location}[#{@key}]."
50
+ error_message += " Valid Modal(s): #{valid_modals}"
51
+ error_messages.push(error_message)
52
+ end
49
53
  end
50
54
  end
51
55
  end
52
56
  end
53
57
  end
54
- end
58
+ end
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validates tests the a key exists on a composite hash
8
+ # Validates tests the a key exists on a composite hash
8
9
  class ValidatePresenceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
11
12
  @key = args.fetch :key
12
13
 
13
14
  options = args.fetch :args, {}
14
- options = (options.is_a?(Hash)) ? options : {}
15
+ options = options.is_a?(Hash) ? options : {}
15
16
  @unless_presence_of = options.fetch :unless_presence_of, nil
16
17
  end
17
18
 
@@ -19,18 +20,18 @@ module AutomationObject
19
20
  # @param composite_object [Object] Composite object to be tested.
20
21
  # @return [nil] no return on exceptions on failure
21
22
  def validate(composite_object)
22
- #Get the hash value from the composite object
23
- return if composite_object.hash.has_key?(@key)
23
+ # Get the hash value from the composite object
24
+ return if composite_object.hash.key?(@key)
24
25
 
25
- #Do unless_presence_of check
26
+ # Do unless_presence_of check
26
27
  if @unless_presence_of
27
- return if composite_object.hash.has_key?(@unless_presence_of)
28
+ return if composite_object.hash.key?(@unless_presence_of)
28
29
  end
29
30
 
30
- self.error_messages.push("Required Key Missing: #{@key}, at: #{composite_object.location}.")
31
+ error_messages.push("Required Key Missing: #{@key}, at: #{composite_object.location}.")
31
32
  end
32
33
  end
33
34
  end
34
35
  end
35
36
  end
36
- end
37
+ end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests that a screen is defined when it is called elsewhere through a hook
8
+ # Validator that tests that a screen is defined when it is called elsewhere through a hook
8
9
  class ValidateScreenPresenceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
@@ -15,41 +16,44 @@ module AutomationObject
15
16
  # @param composite_object [Object] Composite object to be tested.
16
17
  # @return [nil] no return on exceptions on failure
17
18
  def validate(composite_object)
18
- #Get the hash value from the composite object
19
+ # Get the hash value from the composite object
19
20
  target_value = composite_object.hash[@key]
20
21
 
21
22
  return unless target_value
22
23
 
23
- target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
24
+ target_values = target_value.is_a?(Array) ? target_value : [target_value]
24
25
 
25
- valid_screens = self.find_screens(composite_object)
26
-
27
- target_values.each { |screen|
28
- screen = screen.to_sym
29
- next if valid_screens.include?(screen)
30
-
31
- error_message = "Invalid Screen: #{screen}, at: #{composite_object.location}[#{@key}]."
32
- error_message << " Valid Screen(s): #{valid_screens}"
33
- self.error_messages.push(error_message)
34
- }
26
+ valid_screens = find_screens(composite_object)
27
+ populate_errors(target_values, valid_screens, composite_object)
35
28
  end
36
29
 
37
- #Traverses up a composite tree to find :screens in a hash
30
+ private
31
+
32
+ # Traverses up a composite tree to find :screens in a hash
38
33
  # @param composite_object [Object] composite object to traverse up
39
34
  # @return [Array<Symbol>] array of screen names
40
35
  def find_screens(composite_object)
41
- #Using the hash instead of the method because lower nodes will get validated
42
- #before composite is finished building
43
- if composite_object.hash[:screens].is_a?(Hash)
44
- return composite_object.hash[:screens].keys #Should be Hash with screen names as the keys
45
- elsif composite_object.parent
46
- return self.find_screens(composite_object.parent)
47
- end
36
+ # Using the hash instead of the method because lower nodes will get validated
37
+ # before composite is finished building
38
+ return composite_object.hash[:screens].keys if composite_object.hash[:screens].is_a?(Hash)
39
+
40
+ return find_screens(composite_object.parent) if composite_object.parent
48
41
 
49
- return []
42
+ []
43
+ end
44
+
45
+ def populate_errors(target_values, valid_screens, composite_object)
46
+ target_values.each do |screen|
47
+ screen = screen.to_sym
48
+ next if valid_screens.include?(screen)
49
+
50
+ error_message = "Invalid Screen: #{screen}, at: #{composite_object.location}[#{@key}]."
51
+ error_message += " Valid Screen(s): #{valid_screens}"
52
+ error_messages.push(error_message)
53
+ end
50
54
  end
51
55
  end
52
56
  end
53
57
  end
54
58
  end
55
- end
59
+ end
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'validate'
2
3
 
3
4
  module AutomationObject
4
5
  module BluePrint
5
6
  module HashAdapter
6
7
  module Validators
7
- #Validator that tests that a view is defined when it is called elsewhere through a hook
8
+ # Validator that tests that a view is defined when it is called elsewhere through a hook
8
9
  class ValidateViewPresenceOf < Validate
9
10
  # @param args [Hash] arguments for the validation class
10
11
  def initialize(args)
@@ -15,38 +16,41 @@ module AutomationObject
15
16
  # @param composite_object [Object] Composite object to be tested.
16
17
  # @return [nil] no return on exceptions on failure
17
18
  def validate(composite_object)
18
- #Get the hash value from the composite object
19
+ # Get the hash value from the composite object
19
20
  target_value = composite_object.hash[@key]
20
- target_values = (target_value.is_a?(Array)) ? target_value : [target_value]
21
+ target_values = target_value.is_a?(Array) ? target_value : [target_value]
21
22
 
22
23
  return unless target_value
23
24
 
24
- valid_views = self.find_views(composite_object)
25
+ valid_views = find_views(composite_object)
26
+ populate_errors(target_values, valid_views, composite_object)
27
+ end
28
+
29
+ private
30
+
31
+ # Need to traverse up the composite tree and find views
32
+ def find_views(composite_object)
33
+ # Using the hash instead of the method because lower nodes will get validated
34
+ # before composite is finished building
35
+ return composite_object.hash[:views].keys if composite_object.hash[:views].is_a?(Hash)
36
+
37
+ return find_views(composite_object.parent) if composite_object.parent
25
38
 
26
- target_values.each { |view|
39
+ []
40
+ end
41
+
42
+ def populate_errors(target_values, valid_views, composite_object)
43
+ target_values.each do |view|
27
44
  view = view.to_sym
28
45
  next if valid_views.include?(view)
29
46
 
30
47
  error_message = "Invalid View: #{view}, at: #{composite_object.location}[#{@key}]."
31
- error_message << " Valid Views(s): #{valid_views}"
32
- self.error_messages.push(error_message)
33
- }
34
- end
35
-
36
- #Need to traverse up the composite tree and find views
37
- def find_views(composite_object)
38
- #Using the hash instead of the method because lower nodes will get validated
39
- #before composite is finished building
40
- if composite_object.hash[:views].is_a?(Hash)
41
- return composite_object.hash[:views].keys #Should be Hash with view names as the keys
42
- elsif composite_object.parent
43
- return self.find_views(composite_object.parent)
48
+ error_message += " Valid Views(s): #{valid_views}"
49
+ error_messages.push(error_message)
44
50
  end
45
-
46
- return []
47
51
  end
48
52
  end
49
53
  end
50
54
  end
51
55
  end
52
- end
56
+ end