henry-container 0.0.20 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/henry-ruby-container +2 -0
- data/lib/henry/container/version.rb +1 -1
- data/lib/henry/container.rb +57 -9
- data/lib/henry/task.rb +26 -1
- metadata +2 -2
data/bin/henry-ruby-container
CHANGED
@@ -21,6 +21,8 @@ BANNER
|
|
21
21
|
opt :"out-dir", "Custom dir path where the results will be written", :default => '.'
|
22
22
|
opt :in, "Custom name for the input file.", :default => 'in.henry'
|
23
23
|
opt :"in-dir", "Custom dir path where the input will be read from.", :default => '.'
|
24
|
+
opt :hints, "Custom name for the task hints (tasks to be executed) file.", :default => 'task.hints'
|
25
|
+
opt :"hints-dir", "Custom dir path where the task hints (tasks to be executed) will be read from.", :default => '.'
|
24
26
|
end
|
25
27
|
|
26
28
|
Henry::Container.new(opts).execute
|
data/lib/henry/container.rb
CHANGED
@@ -20,8 +20,8 @@ module Henry
|
|
20
20
|
def execute
|
21
21
|
self.before_execution
|
22
22
|
|
23
|
-
self.
|
24
|
-
task.execute(self.task_params(task.name))
|
23
|
+
self.tasks.each do |task|
|
24
|
+
self.task_results << task.execute(self.task_params(task.name)) if task.enabled?
|
25
25
|
end
|
26
26
|
|
27
27
|
self.update_results
|
@@ -59,12 +59,16 @@ module Henry
|
|
59
59
|
def output_file_path
|
60
60
|
"#{@opts[:"out-dir"]}/#{@opts[:out]}"
|
61
61
|
end
|
62
|
+
|
63
|
+
# Returns the task hints file path based on the given options.
|
64
|
+
#
|
65
|
+
# @return [String] the task hints file path.
|
66
|
+
def hints_file_path
|
67
|
+
"#{@opts[:"hints-dir"]}/#{@opts[:hints]}"
|
68
|
+
end
|
62
69
|
|
63
70
|
# Executes required validations before execution.
|
64
71
|
def before_execution
|
65
|
-
unless File.exists?(self.input_file_path)
|
66
|
-
abort "#{"'#{self.input_file_path}' file does not exist.".red}\n #{'*'.red} If running isolated make sure to create it first.\n #{'*'.red} If running from Henry contact us at henry@despegar.it."
|
67
|
-
end
|
68
72
|
|
69
73
|
unless File.exists?('henry-context.yml')
|
70
74
|
abort "'henry-context.yml' file does not exist. You need it in order to execute a Henry compatible test.".red
|
@@ -72,11 +76,23 @@ module Henry
|
|
72
76
|
|
73
77
|
end
|
74
78
|
|
75
|
-
#
|
79
|
+
# Returns the execution params.
|
76
80
|
#
|
77
81
|
# @return [{String => String}] the execution params.
|
78
82
|
def params
|
79
|
-
@params ||=
|
83
|
+
@params ||= self.load_params
|
84
|
+
|
85
|
+
if File.exists?(self.input_file_path)
|
86
|
+
@params ||= JSON.parse(File.read(self.input_file_path))
|
87
|
+
end
|
88
|
+
|
89
|
+
# Loads and parses the @opts[:in] params, if they exists.
|
90
|
+
#
|
91
|
+
# @return [{String => String}] the execution params.
|
92
|
+
def load_params
|
93
|
+
return {} unless File.exists?(self.input_file_path)
|
94
|
+
|
95
|
+
JSON.parse(File.read(self.input_file_path))
|
80
96
|
end
|
81
97
|
|
82
98
|
# Returns the default params.
|
@@ -84,7 +100,7 @@ module Henry
|
|
84
100
|
#
|
85
101
|
# @return [Hash] the default params.
|
86
102
|
def default_params
|
87
|
-
@default_params ||= self.params['all']
|
103
|
+
@default_params ||= (self.params['all'] || {})
|
88
104
|
end
|
89
105
|
|
90
106
|
# Returns the custom params for the given task.
|
@@ -96,6 +112,23 @@ module Henry
|
|
96
112
|
self.default_params.merge(self.params[task_name] || {})
|
97
113
|
end
|
98
114
|
|
115
|
+
|
116
|
+
# Returns de task hints (tasks to be executed) or an empty array if they are not defined.
|
117
|
+
#
|
118
|
+
# @return [<String>] the task hints
|
119
|
+
def task_hints
|
120
|
+
@task_hints ||= self.load_task_hints
|
121
|
+
end
|
122
|
+
|
123
|
+
# Loads and parses the @opts[:hints] params, if they exists.
|
124
|
+
#
|
125
|
+
# @return [<String>] the execution params.
|
126
|
+
def load_task_hints
|
127
|
+
return [] unless File.exists?(self.hints_file_path)
|
128
|
+
|
129
|
+
JSON.parse(File.read(self.hints_file_path))
|
130
|
+
end
|
131
|
+
|
99
132
|
# Load and parses the henry-context.yml params.
|
100
133
|
#
|
101
134
|
# @return [{String => String}] the execution context.
|
@@ -107,7 +140,22 @@ module Henry
|
|
107
140
|
#
|
108
141
|
# @return [<Task>] tasks to be executed.
|
109
142
|
def tasks
|
110
|
-
@tasks ||= self.
|
143
|
+
@tasks ||= self.build_tasks
|
144
|
+
end
|
145
|
+
|
146
|
+
# Builds and disables the Tasks to be executed based on the context and hints.
|
147
|
+
#
|
148
|
+
# @return [<Task>] tasks to be executed.
|
149
|
+
def build_tasks
|
150
|
+
tasks = self.context.tasks.collect do |task_data|
|
151
|
+
Task.create(task_data["name"], task_data)
|
152
|
+
end
|
153
|
+
|
154
|
+
return tasks if self.task_hints.empty?
|
155
|
+
|
156
|
+
tasks.each do |task|
|
157
|
+
task.disable! unless self.task_hints.include? task.name
|
158
|
+
end
|
111
159
|
end
|
112
160
|
|
113
161
|
# Returns the execution's current results.
|
data/lib/henry/task.rb
CHANGED
@@ -7,7 +7,7 @@ module Henry
|
|
7
7
|
class Task
|
8
8
|
|
9
9
|
# Accessors for name and data
|
10
|
-
attr_accessor :name, :data
|
10
|
+
attr_accessor :name, :data, :enabled
|
11
11
|
|
12
12
|
# Returns an instance of the target Task class.
|
13
13
|
# @note Factory to create XTask instances.
|
@@ -21,6 +21,31 @@ module Henry
|
|
21
21
|
def initialize(name, data)
|
22
22
|
self.name = name
|
23
23
|
self.data = OpenStruct.new(data)
|
24
|
+
self.enabled = true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns true whenever the Task is enabled.
|
28
|
+
#
|
29
|
+
# @return [True,False]
|
30
|
+
def enabled?
|
31
|
+
self.enabled
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns true whenever the Task is disabled.
|
35
|
+
#
|
36
|
+
# @return [True,False]
|
37
|
+
def disabled?
|
38
|
+
!self.enabled?
|
39
|
+
end
|
40
|
+
|
41
|
+
# Makes the Task enabled
|
42
|
+
def enable!
|
43
|
+
self.enabled = true
|
44
|
+
end
|
45
|
+
|
46
|
+
# Makes the Task disabled
|
47
|
+
def disable!
|
48
|
+
self.enabled = false
|
24
49
|
end
|
25
50
|
|
26
51
|
# Nothing to be done here yet...
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: henry-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|