automation_object 0.0.4 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/automation_object.rb +14 -72
- data/lib/automation_object/blue_print.rb +37 -100
- data/lib/automation_object/blue_print/composite/automatic_onload_modal.rb +28 -0
- data/lib/automation_object/blue_print/composite/base.rb +18 -0
- data/lib/automation_object/blue_print/composite/custom_method.rb +23 -0
- data/lib/automation_object/blue_print/composite/element.rb +20 -0
- data/lib/automation_object/blue_print/composite/element_array.rb +21 -0
- data/lib/automation_object/blue_print/composite/element_hash.rb +26 -0
- data/lib/automation_object/blue_print/composite/helpers/element_helper.rb +33 -0
- data/lib/automation_object/blue_print/composite/helpers/multiple_elements_helper.rb +18 -0
- data/lib/automation_object/blue_print/composite/hook.rb +31 -0
- data/lib/automation_object/blue_print/composite/hook_action.rb +84 -0
- data/lib/automation_object/blue_print/composite/hook_element_requirements.rb +39 -0
- data/lib/automation_object/blue_print/composite/modal.rb +56 -0
- data/lib/automation_object/blue_print/composite/screen.rb +61 -0
- data/lib/automation_object/blue_print/composite/top.rb +51 -0
- data/lib/automation_object/blue_print/composite/view.rb +48 -0
- data/lib/automation_object/blue_print/hash_adapter.rb +17 -0
- data/lib/automation_object/blue_print/hash_adapter/automatic_onload_modal.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/composite.rb +93 -0
- data/lib/automation_object/blue_print/hash_adapter/custom_method.rb +30 -0
- data/lib/automation_object/blue_print/hash_adapter/element.rb +34 -0
- data/lib/automation_object/blue_print/hash_adapter/element_array.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/element_hash.rb +43 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/element_helper.rb +59 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/multiple_elements_helper.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_error.rb +26 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validation_helper.rb +99 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate.rb +23 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_allowed_keys.rb +31 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_element_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_instance_of.rb +39 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_modal_presence_of.rb +54 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_presence_of.rb +36 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_screen_presence_of.rb +55 -0
- data/lib/automation_object/blue_print/hash_adapter/helpers/validators/validate_view_presence_of.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/hook.rb +35 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_action.rb +134 -0
- data/lib/automation_object/blue_print/hash_adapter/hook_element_requirements.rb +64 -0
- data/lib/automation_object/blue_print/hash_adapter/modal.rb +52 -0
- data/lib/automation_object/blue_print/hash_adapter/screen.rb +91 -0
- data/lib/automation_object/blue_print/hash_adapter/top.rb +63 -0
- data/lib/automation_object/blue_print/hash_adapter/view.rb +29 -0
- data/lib/automation_object/blue_print/helpers/file_helper.rb +38 -0
- data/lib/automation_object/blue_print/yaml_adapter.rb +50 -0
- data/lib/automation_object/driver.rb +44 -0
- data/lib/automation_object/driver/appium_adapter/driver.rb +150 -0
- data/lib/automation_object/driver/appium_adapter/element.rb +118 -0
- data/lib/automation_object/driver/base.rb +11 -0
- data/lib/automation_object/driver/driver.rb +69 -245
- data/lib/automation_object/driver/element.rb +51 -210
- data/lib/automation_object/driver/helpers/selenium_driver_helper.rb +41 -0
- data/lib/automation_object/driver/helpers/selenium_element_helper.rb +138 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/driver.rb +83 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/element.rb +66 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/form.rb +29 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/helpers/driver_element_helper.rb +52 -0
- data/lib/automation_object/driver/nokogiri_adapter/backup/session.rb +115 -0
- data/lib/automation_object/driver/nokogiri_adapter/driver.rb +104 -0
- data/lib/automation_object/driver/nokogiri_adapter/element.rb +85 -0
- data/lib/automation_object/driver/nokogiri_adapter/error.rb +17 -0
- data/lib/automation_object/driver/selenium_adapter/driver.rb +143 -0
- data/lib/automation_object/driver/selenium_adapter/element.rb +116 -0
- data/lib/automation_object/dsl.rb +33 -0
- data/lib/automation_object/dsl/blue_print_adapter.rb +16 -0
- data/lib/automation_object/dsl/blue_print_adapter/composite.rb +54 -0
- data/lib/automation_object/dsl/blue_print_adapter/element.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_array.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/element_hash.rb +14 -0
- data/lib/automation_object/dsl/blue_print_adapter/modal.rb +23 -0
- data/lib/automation_object/dsl/blue_print_adapter/screen.rb +26 -0
- data/lib/automation_object/dsl/blue_print_adapter/top.rb +19 -0
- data/lib/automation_object/dsl/models.rb +18 -0
- data/lib/automation_object/dsl/proxies/element.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_array.rb +16 -0
- data/lib/automation_object/dsl/proxies/element_hash.rb +16 -0
- data/lib/automation_object/dsl/proxies/helpers/composite_helper.rb +74 -0
- data/lib/automation_object/dsl/proxies/modal.rb +17 -0
- data/lib/automation_object/dsl/proxies/screen.rb +17 -0
- data/lib/automation_object/dsl/proxies/top.rb +17 -0
- data/lib/automation_object/framework.rb +79 -386
- data/lib/automation_object/helpers/composite.rb +95 -0
- data/lib/automation_object/helpers/composite_hook.rb +46 -0
- data/lib/automation_object/helpers/hash.rb +15 -0
- data/lib/automation_object/helpers/reflection_helper.rb +28 -0
- data/lib/automation_object/helpers/string.rb +27 -0
- data/lib/automation_object/proxies/mutex_proxy.rb +63 -0
- data/lib/automation_object/proxies/proxy.rb +20 -0
- data/lib/automation_object/proxies/throttle_proxy.rb +57 -0
- data/lib/automation_object/state.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter.rb +16 -0
- data/lib/automation_object/state/blue_print_adapter/composite.rb +65 -0
- data/lib/automation_object/state/blue_print_adapter/element.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/element_array.rb +25 -0
- data/lib/automation_object/state/blue_print_adapter/element_hash.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/element_proxy.rb +28 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/element_helper.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/screen_manager.rb +137 -0
- data/lib/automation_object/state/blue_print_adapter/helpers/window.rb +39 -0
- data/lib/automation_object/state/blue_print_adapter/hook.rb +56 -0
- data/lib/automation_object/state/blue_print_adapter/hook_action.rb +33 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/action_loop.rb +35 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_screen.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/change_to_previous_screen.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_modal.rb +31 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/close_screen.rb +19 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/element_requirement.rb +34 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/new_screen.rb +37 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/possible_screen_changes.rb +21 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/reset_screen.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/show_modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/sleep.rb +18 -0
- data/lib/automation_object/state/blue_print_adapter/hook_actions/wait_for_elements.rb +20 -0
- data/lib/automation_object/state/blue_print_adapter/modal.rb +26 -0
- data/lib/automation_object/state/blue_print_adapter/screen.rb +32 -0
- data/lib/automation_object/state/blue_print_adapter/top.rb +45 -0
- data/lib/automation_object/state/error.rb +24 -0
- data/lib/automation_object/state/session.rb +38 -0
- data/lib/automation_object/step_definitions.rb +14 -0
- data/lib/automation_object/step_definitions/action.rb +21 -0
- data/lib/automation_object/step_definitions/cache.rb +23 -0
- data/lib/automation_object/step_definitions/element/actions.rb +87 -0
- data/lib/automation_object/step_definitions/element/regex.rb +24 -0
- data/lib/automation_object/step_definitions/element/steps.rb +67 -0
- data/lib/automation_object/step_definitions/parse.rb +39 -0
- data/lib/automation_object/version.rb +1 -1
- metadata +194 -110
- data/lib/automation_object/blue_print_validation/base_validation.rb +0 -44
- data/lib/automation_object/blue_print_validation/common_methods.rb +0 -106
- data/lib/automation_object/blue_print_validation/element_validation.rb +0 -198
- data/lib/automation_object/blue_print_validation/formatted_errors.rb +0 -41
- data/lib/automation_object/blue_print_validation/hook_validation.rb +0 -393
- data/lib/automation_object/blue_print_validation/key_value_constants.rb +0 -75
- data/lib/automation_object/blue_print_validation/modal_validation.rb +0 -37
- data/lib/automation_object/blue_print_validation/screen_modal_common_methods.rb +0 -119
- data/lib/automation_object/blue_print_validation/screen_validation.rb +0 -21
- data/lib/automation_object/blue_print_validation/validation_object.rb +0 -32
- data/lib/automation_object/driver/anonymous.rb +0 -27
- data/lib/automation_object/element/element.rb +0 -145
- data/lib/automation_object/element/element_array.rb +0 -12
- data/lib/automation_object/element/element_cell.rb +0 -126
- data/lib/automation_object/element/element_group.rb +0 -33
- data/lib/automation_object/element/element_hash.rb +0 -25
- data/lib/automation_object/element/element_helpers.rb +0 -29
- data/lib/automation_object/element/element_methods.rb +0 -134
- data/lib/automation_object/element/elements_helpers.rb +0 -204
- data/lib/automation_object/framework/events.rb +0 -8
- data/lib/automation_object/framework/helpers.rb +0 -101
- data/lib/automation_object/framework/print_objects.rb +0 -67
- data/lib/automation_object/framework/screen_monitor.rb +0 -55
- data/lib/automation_object/framework/screen_routing.rb +0 -310
- data/lib/automation_object/framework/window_helpers.rb +0 -181
- data/lib/automation_object/hash.rb +0 -6
- data/lib/automation_object/hook_helpers.rb +0 -27
- data/lib/automation_object/logger.rb +0 -179
- data/lib/automation_object/object.rb +0 -22
- data/lib/automation_object/screen/modal.rb +0 -8
- data/lib/automation_object/screen/screen.rb +0 -209
- data/lib/automation_object/screen/screen_hook_helpers.rb +0 -319
- data/lib/automation_object/screen/screen_modal_helpers.rb +0 -101
- data/lib/automation_object/screen/screen_prompt_helpers.rb +0 -21
- data/lib/automation_object/screen/screen_window_helpers.rb +0 -149
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require_relative 'reflection_helper'
|
|
2
|
+
require_relative 'composite_hook'
|
|
3
|
+
|
|
4
|
+
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
|
|
7
|
+
class Composite
|
|
8
|
+
include CompositeHook
|
|
9
|
+
include ReflectionHelper
|
|
10
|
+
|
|
11
|
+
attr_accessor :name, :parent, :location, :children
|
|
12
|
+
|
|
13
|
+
# @param name [Symbol] name of the object
|
|
14
|
+
# @param parent [Object, nil] parent composite object
|
|
15
|
+
# @param location [String] string location for error/debugging purposes
|
|
16
|
+
def initialize(name = :top, parent = nil, location = 'top')
|
|
17
|
+
self.parent = parent
|
|
18
|
+
self.location = location
|
|
19
|
+
|
|
20
|
+
self.before_create_run
|
|
21
|
+
|
|
22
|
+
self.add_has_one_relationships
|
|
23
|
+
self.add_has_many_relationships
|
|
24
|
+
|
|
25
|
+
self.after_create_run
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def children
|
|
29
|
+
@children ||= {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Get top composite Object
|
|
33
|
+
# @return [AutomationObject::Composite]
|
|
34
|
+
def top
|
|
35
|
+
#Should recursively call top until parent is nil
|
|
36
|
+
return (self.parent == nil) ? self : self.parent.top
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Abstract argument, override
|
|
40
|
+
# @param name [Symbol] name of child
|
|
41
|
+
# @param options [Hash] options for child
|
|
42
|
+
# @return child [Object] return child composite object
|
|
43
|
+
def get_child(name, options)
|
|
44
|
+
raise 'Abstract method'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Abstract argument, override
|
|
48
|
+
# @param name [Symbol] name of child
|
|
49
|
+
# @param options [Hash] options for child
|
|
50
|
+
# @return children [Hash] return children and names
|
|
51
|
+
def get_children(name, options)
|
|
52
|
+
raise 'Abstract method'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def add_has_one_relationships
|
|
56
|
+
self.class.has_one_relationships.each { |name, options|
|
|
57
|
+
self.children[name] = get_child(name, options)
|
|
58
|
+
self.add_attribute(name, self.children[name])
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def add_has_many_relationships
|
|
63
|
+
self.class.has_many_relationships.each { |name, options|
|
|
64
|
+
composite_children = get_children(name, options)
|
|
65
|
+
self.children[name] = composite_children
|
|
66
|
+
self.add_attribute(name, self.children[name])
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class << self
|
|
71
|
+
#Has many children relationship for the composite
|
|
72
|
+
# @param children_name [Symbol] name of the children, should be a BluePrint method
|
|
73
|
+
# @param args [Hash] additional arguments, expects interface
|
|
74
|
+
def has_many(children_name, args)
|
|
75
|
+
self.has_many_relationships[children_name] = args
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @return [Hash] relationships for the composite
|
|
79
|
+
def has_many_relationships
|
|
80
|
+
@has_many_relationships ||= Hash.new
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @param child_name [Symbol] name of key
|
|
84
|
+
# @param args [Hash] arguments
|
|
85
|
+
def has_one(child_name, args)
|
|
86
|
+
self.has_one_relationships[child_name] = args
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# @return [Hash] hash of relationships
|
|
90
|
+
def has_one_relationships
|
|
91
|
+
@has_one_relationships ||= Hash.new
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
#Hooks for composites
|
|
3
|
+
module CompositeHook
|
|
4
|
+
def before_create_run
|
|
5
|
+
self.class.before_create_hooks.each { |before_create_hook|
|
|
6
|
+
self.send(before_create_hook)
|
|
7
|
+
}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def after_create_run
|
|
11
|
+
self.class.after_create_hooks.each { |after_create_hook|
|
|
12
|
+
self.send(after_create_hook)
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param base [Class] class to extend when included
|
|
17
|
+
def self.included(base)
|
|
18
|
+
base.extend(ClassMethods)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#Class level methods
|
|
22
|
+
module ClassMethods
|
|
23
|
+
# @param instance_method [Symbol] method to call
|
|
24
|
+
def after_create(instance_method)
|
|
25
|
+
self.after_create_hooks.push(instance_method)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @return [Array<Symbol>] list of methods to call
|
|
29
|
+
def after_create_hooks
|
|
30
|
+
@after_create_hooks = [] unless @after_create_hooks
|
|
31
|
+
return @after_create_hooks
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @param instance_method [Symbol] method to call
|
|
35
|
+
def before_create(instance_method)
|
|
36
|
+
self.before_create_hooks.push(instance_method)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [Array<Symbol>] list of methods to call
|
|
40
|
+
def before_create_hooks
|
|
41
|
+
@before_create_hooks = [] unless @before_create_hooks
|
|
42
|
+
return @before_create_hooks
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#Hash class method additions
|
|
2
|
+
class ::Hash
|
|
3
|
+
def deep_merge(second)
|
|
4
|
+
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
|
5
|
+
self.merge(second, &merger)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def symbolize_keys_deep!(h = self)
|
|
9
|
+
h.keys.each do |k|
|
|
10
|
+
ks = k.respond_to?(:to_sym) ? k.to_sym : k
|
|
11
|
+
h[ks] = h.delete k # Preserve order even when k == ks
|
|
12
|
+
symbolize_keys_deep! h[ks] if h[ks].is_a?(Hash)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
#Helper module for adding attributes/alias to classes dynamically
|
|
3
|
+
#Reflection/MetaProgramming
|
|
4
|
+
module ReflectionHelper
|
|
5
|
+
# @param name [String, Symbol] name of attribute to add
|
|
6
|
+
# @param value [Object] value of attribute
|
|
7
|
+
def add_attribute(name, value)
|
|
8
|
+
name = name.to_s
|
|
9
|
+
alias_name = name + '?' if name.gsub!(/\?$/, '')
|
|
10
|
+
|
|
11
|
+
self.class.send(:attr_accessor, name)
|
|
12
|
+
instance_variable_set("@#{name}", value)
|
|
13
|
+
|
|
14
|
+
self.add_alias(alias_name, name) if alias_name
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @param alias_name [Symbol, String] name of alias to add
|
|
18
|
+
# @param attribute_name [Symbol, String] attribute to link to
|
|
19
|
+
def add_alias(alias_name, attribute_name)
|
|
20
|
+
singleton_class = class << self;
|
|
21
|
+
self;
|
|
22
|
+
end
|
|
23
|
+
singleton_class.send(:define_method, alias_name) do
|
|
24
|
+
instance_variable_get("@#{attribute_name}")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#String class method additions
|
|
2
|
+
class ::String
|
|
3
|
+
def valid_url?
|
|
4
|
+
uri = URI.parse(self)
|
|
5
|
+
if uri.kind_of?(URI::HTTP)
|
|
6
|
+
if self.match(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix)
|
|
7
|
+
return true
|
|
8
|
+
else
|
|
9
|
+
return false
|
|
10
|
+
end
|
|
11
|
+
else
|
|
12
|
+
return false
|
|
13
|
+
end
|
|
14
|
+
rescue URI::InvalidURIError
|
|
15
|
+
return false
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def join_url(url)
|
|
19
|
+
full_url = self.chomp('/') + url.reverse.chomp('/').reverse
|
|
20
|
+
return full_url
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def pascalize
|
|
24
|
+
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
|
25
|
+
self.split('_').map { |part| part.capitalize }.join
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require_relative 'proxy'
|
|
2
|
+
|
|
3
|
+
module AutomationObject
|
|
4
|
+
module Proxies
|
|
5
|
+
#Proxy class for protecting object with Mutex
|
|
6
|
+
class MutexProxy < Proxy
|
|
7
|
+
def initialize(subject)
|
|
8
|
+
super
|
|
9
|
+
|
|
10
|
+
@mutexes = [Mutex.new]
|
|
11
|
+
@skip_protection_classes = [TrueClass, FalseClass, String, Numeric, Array, Hash, Class, NilClass, Symbol]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_mutex(mutex_object)
|
|
15
|
+
unless mutex_object.is_a?(Mutex)
|
|
16
|
+
raise ArgumentError, 'Expecting mutex_object argument to be a Mutex object'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
@mutexes << mutex_object
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete_mutex(mutex_object)
|
|
23
|
+
unless mutex_object.is_a?(Mutex)
|
|
24
|
+
raise ArgumentError, 'Expecting mutex_object argument to be a Mutex object'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@mutexes.delete(mutex_object)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def method_missing(method_symbol, *args, &block)
|
|
31
|
+
exec_procedures = Array.new
|
|
32
|
+
exec_procedures.push(lambda {
|
|
33
|
+
execution_return = @subject.send(method_symbol, *args, &block)
|
|
34
|
+
return self.protect_object(execution_return)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
index = 0
|
|
38
|
+
@mutexes.each { |mutex|
|
|
39
|
+
index += 1
|
|
40
|
+
exec_procedures.push(lambda {
|
|
41
|
+
mutex.synchronize do
|
|
42
|
+
index -= 1
|
|
43
|
+
exec_procedures[index].call
|
|
44
|
+
end
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return exec_procedures.last.call
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def protect_object(object)
|
|
52
|
+
return object if @skip_protection_classes.include?(object.class)
|
|
53
|
+
protected_object = MutexProxy.new(object)
|
|
54
|
+
|
|
55
|
+
@mutexes.each { |mutex|
|
|
56
|
+
protected_object.add_mutex(mutex)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return protected_object
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module AutomationObject
|
|
2
|
+
module Proxies
|
|
3
|
+
#Base Proxy class for getting between another
|
|
4
|
+
class Proxy
|
|
5
|
+
instance_methods.each { |instance_method|
|
|
6
|
+
unless instance_method =~ /(^__|^send$|^object_id)/
|
|
7
|
+
undef_method instance_method
|
|
8
|
+
end
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
def initialize(subject)
|
|
12
|
+
@subject = subject
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def method_missing(method_symbol, *args, &block)
|
|
16
|
+
return @subject.send(method_symbol, *args, &block)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require_relative 'proxy'
|
|
2
|
+
|
|
3
|
+
module AutomationObject
|
|
4
|
+
module Proxies
|
|
5
|
+
#Proxy class to throttle methods on the subject
|
|
6
|
+
class ThrottleProxy < Proxy
|
|
7
|
+
def initialize(subject)
|
|
8
|
+
super
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def throttle_methods
|
|
12
|
+
@throttle_methods ||= Hash.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def method_missing(method_symbol, *args, &block)
|
|
16
|
+
start_time = Time.new.to_f
|
|
17
|
+
execution_return = @subject.send(method_symbol, *args, &block)
|
|
18
|
+
self.throttle_speed(method_symbol, start_time)
|
|
19
|
+
return execution_return
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_method_throttle(method_symbol, time)
|
|
23
|
+
unless method_symbol.is_a?(Symbol)
|
|
24
|
+
raise ArgumentError, 'Expecting method_symbol argument to be a Symbol'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
unless time.is_a?(Numeric)
|
|
28
|
+
raise ArgumentError, 'Expecting time argument to be Numeric'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
unless @subject.respond_to?(method_symbol)
|
|
32
|
+
raise ArgumentError, "Expecting object to respond_to? #{method_symbol}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
self.throttle_methods[method_symbol] = time
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
#Delete throttle that exists
|
|
39
|
+
# @param method_symbol [Symbol] method symbol to remove throttle from
|
|
40
|
+
def delete_method_throttle(method_symbol)
|
|
41
|
+
self.throttle_methods.delete(method_symbol)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
#Method to sleep the difference between actual and throttle time
|
|
45
|
+
# @param method_symbol [Symbol] method that is to be throttled
|
|
46
|
+
# @param start_time [Float] start time as float
|
|
47
|
+
# @return [nil]
|
|
48
|
+
def throttle_speed(method_symbol, start_time)
|
|
49
|
+
return unless self.throttle_methods.has_key?(method_symbol)
|
|
50
|
+
total_time_taken = Time.new.to_f - start_time
|
|
51
|
+
|
|
52
|
+
sleep_time = self.throttle_methods[method_symbol] - total_time_taken
|
|
53
|
+
sleep(sleep_time) if sleep_time > 0
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative 'state/session'
|
|
2
|
+
|
|
3
|
+
module AutomationObject
|
|
4
|
+
#State Port, following port/adapter pattern
|
|
5
|
+
#BluePrintAdapter adapts the state to the blueprint
|
|
6
|
+
module State
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
# @return [AutomationObject::State::BluePrintAdapter::Top]
|
|
10
|
+
def adapter
|
|
11
|
+
return @adapter if @adapter
|
|
12
|
+
self.adapter = :blue_print
|
|
13
|
+
@adapter
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Sets adapter const will append _adapter if needed
|
|
17
|
+
# @param adapter_name [String] name of adapter wanted for composite creation
|
|
18
|
+
def adapter=(adapter_name)
|
|
19
|
+
adapter_name = adapter_name.to_s
|
|
20
|
+
adapter_name << '_adapter' unless adapter_name.match(/_adapter$/)
|
|
21
|
+
adapter_const = adapter_name.pascalize
|
|
22
|
+
|
|
23
|
+
require_relative "state/#{adapter_name}"
|
|
24
|
+
@adapter = AutomationObject::State.const_get("#{adapter_const}")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Creates/returns a new session, attaches driver, and composite adapter
|
|
28
|
+
# Will use a composite to direct the other layers (ie BluePrint)
|
|
29
|
+
# @param blue_prints [AutomationObject::BluePrint::Composite::Top] Top composite interface
|
|
30
|
+
# @param driver [AutomationObject::Driver::Driver] driver interface
|
|
31
|
+
# @return [AutomationObject::State::Session] Session instance
|
|
32
|
+
def new(blue_prints, driver)
|
|
33
|
+
adapter_composite = self.adapter.build(blue_prints, driver)
|
|
34
|
+
return Session.new(driver: args.fetch(driver), composite: adapter_composite)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require_relative 'blue_print_adapter/top'
|
|
2
|
+
|
|
3
|
+
module AutomationObject
|
|
4
|
+
module State
|
|
5
|
+
#State adapter for building DSL framework
|
|
6
|
+
#Will work with the blueprints and adapter to accomplish the goal of maintaining the state
|
|
7
|
+
#And give control of operations via the DSL
|
|
8
|
+
module BluePrintAdapter
|
|
9
|
+
# @param args [Hash] expects :blue_prints, :driver
|
|
10
|
+
# @return [AutomationObject::State::BlueAdapter::Top]
|
|
11
|
+
def self.build(blue_prints, driver)
|
|
12
|
+
return Top.new(args.fetch(:blue_prints), args.fetch(:driver))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require_relative '../../helpers/composite'
|
|
2
|
+
#require_relative 'top'
|
|
3
|
+
#require_relative 'screen'
|
|
4
|
+
|
|
5
|
+
module AutomationObject
|
|
6
|
+
module State
|
|
7
|
+
module BluePrintAdapter
|
|
8
|
+
#Parent composite class
|
|
9
|
+
class Composite < AutomationObject::Composite
|
|
10
|
+
attr_accessor :blue_prints, :driver
|
|
11
|
+
|
|
12
|
+
# @param blue_prints [AutomationObject::BluePrint::Composite] blue print composite
|
|
13
|
+
# @param driver [AutomationObject::Driver] driver
|
|
14
|
+
# @param name [Symbol] name of composite element
|
|
15
|
+
# @param parent [Object, nil] parent composite object
|
|
16
|
+
# @param location [String] string location for error/debugging purposes
|
|
17
|
+
def initialize(blue_prints, driver, name = :top, parent = nil, location = 'top')
|
|
18
|
+
self.blue_prints = blue_prints
|
|
19
|
+
self.driver = driver
|
|
20
|
+
|
|
21
|
+
super(name, parent, location)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Overriding base get_child method
|
|
25
|
+
# @param name [Symbol] name of child
|
|
26
|
+
# @param args [Hash] args
|
|
27
|
+
def get_child(name, args)
|
|
28
|
+
child_location = self.location + "[#{name}]"
|
|
29
|
+
|
|
30
|
+
return args.fetch(:interface).new(self.blue_prints.send(name), self.driver, name, self, child_location)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Overriding base get_children method
|
|
34
|
+
# @param name [Symbol] name of child
|
|
35
|
+
# @param args [Hash] args
|
|
36
|
+
# @return children [Array<Composite>] return children and names
|
|
37
|
+
def get_children(name, args)
|
|
38
|
+
children_hash = Hash.new
|
|
39
|
+
|
|
40
|
+
self.blue_prints.send(name).each { |child_key, child_blue_prints|
|
|
41
|
+
child_location = self.location + "[#{child_key}]"
|
|
42
|
+
|
|
43
|
+
children_hash[child_key] = args.fetch(:interface).new(child_blue_prints,
|
|
44
|
+
self.driver,
|
|
45
|
+
name,
|
|
46
|
+
self,
|
|
47
|
+
child_location)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return children_hash
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Recursive function to reach parent screen
|
|
54
|
+
# Can return nil if above a screen!
|
|
55
|
+
# @return [AutomationObject::State::BluePrintAdapter::Screen,nil]
|
|
56
|
+
def screen
|
|
57
|
+
return nil if self.is_a?(Top)
|
|
58
|
+
|
|
59
|
+
#Should recursively call top until parent is nil
|
|
60
|
+
return (self.is_a?(Screen)) ? self : self.parent.screen
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|