rcoli 0.5.8 → 0.5.9

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.
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rcoli (0.5.8)
4
+ rcoli (0.5.9)
5
5
  highline (~> 1.6.11)
6
+ paint (= 0.8.5)
6
7
 
7
8
  GEM
8
9
  remote: http://rubygems.org/
9
10
  specs:
10
11
  highline (1.6.15)
12
+ paint (0.8.5)
11
13
  rake (10.0.3)
12
14
 
13
15
  PLATFORMS
@@ -1,5 +1,6 @@
1
1
  require 'logger'
2
2
  require 'singleton'
3
+ require 'paint'
3
4
 
4
5
  module RCoLi
5
6
 
@@ -19,7 +20,19 @@ module RCoLi
19
20
  @log = Logger.new(STDOUT)
20
21
  @log.level = Logger::INFO
21
22
  @log.formatter = proc do |severity, datetime, progname, msg|
22
- "#{msg}\n"
23
+ case severity
24
+ when "DEBUG"
25
+ color = 'gray27'
26
+ else
27
+ color = :white
28
+ end
29
+
30
+ if STDOUT.tty?
31
+ Paint["#{msg}\n", color]
32
+ else
33
+ "#{msg}\n"
34
+ end
35
+
23
36
  end
24
37
  end
25
38
 
@@ -29,8 +42,46 @@ module RCoLi
29
42
 
30
43
  end
31
44
 
45
+ class SystemExecutor
46
+
47
+ include Singleton
48
+
49
+ def initialize
50
+ end
51
+
52
+ def register(file)
53
+ @source = file
54
+ log.debug("Loading commands from file #{file}")
55
+ @commands = YAML::load(File.open(file))
56
+ end
57
+
58
+ def execute(command, *args)
59
+ cmnd = @commands[command.to_s]
60
+ if cmnd
61
+ cmnd.scan(/\$\{([^\s]+)\}/).each do |s|
62
+ context = args[0]
63
+ (s[0].split('.').each{|key| context = (context.is_a? Hash) ? context[key] : nil})
64
+ cmnd = cmnd.sub("${#{s[0]}}", context) if context if context
65
+ end
66
+ log.debug("EXEC: #{cmnd}")
67
+ system(cmnd)
68
+ else
69
+ raise ApplicationError, "The command #{command} isn't configured. Check the file #{@source}"
70
+ end
71
+ end
72
+
73
+ end
74
+
32
75
  end
33
76
 
34
77
  def log
35
78
  RCoLi::Log.instance.logger
36
79
  end
80
+
81
+ def sysexec(command, *args)
82
+ RCoLi::SystemExecutor.instance.execute(command, args[0])
83
+ end
84
+
85
+ def load_commands(file)
86
+ RCoLi::SystemExecutor.instance.register(file)
87
+ end
@@ -1,5 +1,5 @@
1
1
  module RCoLi
2
2
 
3
- VERSION = '0.5.8'
3
+ VERSION = '0.5.9'
4
4
 
5
5
  end
@@ -15,6 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.require_paths = ["lib"]
16
16
 
17
17
  s.add_runtime_dependency("highline", "~> 1.6.11")
18
-
18
+ s.add_runtime_dependency('paint', '0.8.5')
19
19
  s.add_development_dependency("rake")
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcoli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.5.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.6.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: paint
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.5
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rake
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -78,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
94
  version: '0'
79
95
  segments:
80
96
  - 0
81
- hash: 2822556458840030411
97
+ hash: -3080644431279771891
82
98
  required_rubygems_version: !ruby/object:Gem::Requirement
83
99
  none: false
84
100
  requirements:
@@ -87,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
103
  version: '0'
88
104
  segments:
89
105
  - 0
90
- hash: 2822556458840030411
106
+ hash: -3080644431279771891
91
107
  requirements: []
92
108
  rubyforge_project:
93
109
  rubygems_version: 1.8.24