henry-container 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module Henry
3
3
  class Container
4
4
 
5
5
  # Current Gem version
6
- VERSION = '0.0.48'
6
+ VERSION = '0.0.49'
7
7
 
8
8
  end
9
9
 
@@ -24,7 +24,9 @@ module Henry
24
24
 
25
25
  self.tasks.select {|task| task.enabled?}.each do |task|
26
26
  task.configure(self.task_params(task.name))
27
+ task.before_execute
27
28
  task.execute
29
+ task.after_execute
28
30
  self.tasks_results << task.report
29
31
  end
30
32
 
@@ -1,4 +1,8 @@
1
+ require 'drb/drb'
2
+
1
3
  require 'henry/input'
4
+ require 'henry/logger'
5
+ require 'henry/logger_service'
2
6
 
3
7
  module Henry
4
8
 
@@ -13,6 +17,13 @@ module Henry
13
17
  @@params ||= Input.import!.params
14
18
  end
15
19
 
20
+ # Gets the Task Logger instance vis DBr.
21
+ #
22
+ # @return [Logger] the Task Logger instance.
23
+ def self.logger
24
+ return DRbObject.new_with_uri(LoggerService::DRB_URI)
25
+ end
26
+
16
27
  end
17
28
 
18
29
  end
@@ -4,7 +4,7 @@ module Henry
4
4
  class Execution
5
5
 
6
6
  # Accessors for task_name, code, message, output and backtrace.
7
- attr_accessor :task_name, :code, :message, :output, :backtrace
7
+ attr_accessor :task_name, :code, :message, :output, :backtrace, :log
8
8
 
9
9
  # Returns the json ready hash report of the Task Execution
10
10
  #
@@ -17,7 +17,8 @@ module Henry
17
17
  returnedData: {
18
18
  output: self.output,
19
19
  backtrace: self.backtrace
20
- }
20
+ },
21
+ log: self.log
21
22
  }
22
23
  end
23
24
 
@@ -0,0 +1,63 @@
1
+ module Henry
2
+
3
+ # Henry Logger
4
+ # Grants the ability log messages under several levels during execution time
5
+ class Logger
6
+
7
+ attr_accessor :storage
8
+
9
+ # Appends the message as a log entry under the info level.
10
+ #
11
+ # @param [String] message the message to be appended.
12
+ def info(message)
13
+ puts 'aaaa'
14
+ self.log(:info, message)
15
+ end
16
+
17
+ # Appends the message as a log entry under the warm level.
18
+ #
19
+ # @param [String] message the message to be appended.
20
+ def warn(message)
21
+ self.log(:warn, message)
22
+ end
23
+
24
+ # Appends the message as a log entry under the error level.
25
+ #
26
+ # @param [String] message the message to be appended.
27
+ def error(message)
28
+ self.log(:error, message)
29
+ end
30
+
31
+ # Return the stored logs.
32
+ def log_as_hash
33
+ self.get_storage
34
+ end
35
+
36
+ # Returns the storage
37
+ #
38
+ # @return [Hash] the storage.
39
+ def get_storage
40
+ @storage ||= {}
41
+ end
42
+
43
+ # Returns the storage of the given level
44
+ #
45
+ # @param [Symbol] level the target log level.
46
+ # @return [Array] the logs collection of the given level.
47
+ def storage(level)
48
+ self.get_storage[level] ||= []
49
+ end
50
+
51
+ protected
52
+
53
+ # Appends the message as a log entry under the given level.
54
+ #
55
+ # @param [Symbol] level the log level to append the message.
56
+ # @param [String] message to be appended.
57
+ def log(level, message)
58
+ self.storage(level) << message
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,22 @@
1
+ module Henry
2
+
3
+ class LoggerService
4
+
5
+ # Uri where the service will e listening.
6
+ DRB_URI = 'druby://localhost:8787'
7
+
8
+ # Starts the logger service sharing the given Logger.
9
+ #
10
+ # @param [Logger] logger the Logger isntance to be shared.
11
+ def self.start(logger)
12
+ DRb.start_service(DRB_URI, logger)
13
+ end
14
+
15
+ # Stops the logger service.
16
+ def self.stop
17
+ DRb.stop_service
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -22,11 +22,13 @@ module Henry
22
22
  self.execution.code = 'OK'
23
23
  self.execution.message = 'OK'
24
24
  self.execution.output = File.open(OUT_PATH, 'r').read
25
+ self.execution.log = self.logger.log_as_hash
25
26
  rescue Exception => e
26
27
  self.execution.code = 'ERROR'
27
28
  self.execution.message = 'ERROR'
28
29
  self.execution.output = File.open(OUT_PATH, 'r').read
29
30
  self.execution.backtrace = e.message
31
+ self.execution.log = self.logger.log_as_hash
30
32
  end
31
33
  end
32
34
 
@@ -22,11 +22,13 @@ module Henry
22
22
  self.execution.code = 'OK'
23
23
  self.execution.message = 'OK'
24
24
  self.execution.output = File.open(OUT_PATH, 'r').read
25
+ self.execution.log = self.logger.log_as_hash
25
26
  rescue Exception => e
26
27
  self.execution.code = 'ERROR'
27
28
  self.execution.message = 'ERROR'
28
29
  self.execution.output = File.open(OUT_PATH, 'r').read
29
30
  self.execution.backtrace = e.message
31
+ self.execution.log = self.logger.log_as_hash
30
32
  end
31
33
  end
32
34
 
data/lib/henry/task.rb CHANGED
@@ -25,6 +25,16 @@ module Henry
25
25
  self.execution.task_name = self.name
26
26
  end
27
27
 
28
+ # Code to be run just before the execution
29
+ def before_execute
30
+ LoggerService.start(self.logger)
31
+ end
32
+
33
+ # Code to be run justafter the execution
34
+ def after_execute
35
+ LoggerService.stop
36
+ end
37
+
28
38
  # Returns the json ready hash report of the task execution.
29
39
  #
30
40
  # @return [Hash]
@@ -46,6 +56,13 @@ module Henry
46
56
  @execution ||= Execution.new
47
57
  end
48
58
 
59
+ # Returns the Task Logger.
60
+ #
61
+ # @return [Logger]
62
+ def logger
63
+ @logger ||= Logger.new
64
+ end
65
+
49
66
  # Returns true whenever the Task is enabled.
50
67
  #
51
68
  # @return [True,False]
data/lib/henry.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  require 'date'
2
+ require 'drb/drb'
2
3
 
3
4
  require_relative 'henry/task'
4
5
  require_relative 'henry/container'
5
6
  require_relative 'henry/execution'
6
7
  require_relative 'henry/input'
8
+ require_relative 'henry/logger'
9
+ require_relative 'henry/logger_service'
7
10
 
8
11
  # Henry
9
12
  module Henry
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.48
4
+ version: 0.0.49
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-08-23 00:00:00.000000000 Z
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -129,6 +129,8 @@ files:
129
129
  - lib/henry/environment.rb
130
130
  - lib/henry/execution.rb
131
131
  - lib/henry/input.rb
132
+ - lib/henry/logger.rb
133
+ - lib/henry/logger_service.rb
132
134
  - lib/henry/task.rb
133
135
  - lib/henry/task/cucumber_task.rb
134
136
  - lib/henry/task/rspec_task.rb