hammer_cli 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c64a799978261a9f78c6ce7642a7cb82473cbb0a
4
- data.tar.gz: 5893a4bfe3980b8794ea988c3895871625f1de47
3
+ metadata.gz: dc846bf971738baff5d9a47ba375a4faa698ddff
4
+ data.tar.gz: ec7445b7048131184372d9d6aabfa00c2bc27d77
5
5
  SHA512:
6
- metadata.gz: 18db270151afec8b1da636d4a3aa9088090c1b4de705102d8ca877c2c5cccbba65acbaa21f12dcbd2abb685f1bb2e684d6324afab555e6172857544c1c704215
7
- data.tar.gz: 2c860c0406767e951e0d63d11d2c2e4e5c9d992148710110941982f3a0a9e295a8faf0c2983de1a97b5ba864b5f0aec66c851918e561132f99253c6b83e2edee
6
+ metadata.gz: 49c74f5aad4024fd6074135d1d779e2bcf6b9debafddb2879672e938c1c0da0901c88719b70a9872145539d878c3d8660777bb535017436095790c6b2ea4662e
7
+ data.tar.gz: e84343ad493a84d1fb21e8e1cf7e36ffd63b6737fa4179b531b132a3ca3e2f050e969e40b905ad672f2c2f145e111754431fda7f89f3edb17df3b773b6490be2
data/bin/hammer CHANGED
@@ -37,7 +37,8 @@ if preparser.verbose?
37
37
  root_logger.appenders = root_logger.appenders << ::Logging.appenders.stderr(:layout => HammerCLI::Logger::COLOR_LAYOUT)
38
38
  end
39
39
 
40
- hammer_version = Gem.loaded_specs['hammer_cli'].version.to_s
40
+ require 'hammer_cli/version'
41
+ hammer_version = HammerCLI.version.to_s
41
42
  logger.info "Initialization of Hammer CLI (#{hammer_version}) has started..."
42
43
 
43
44
  # log which config was loaded (now when we have logging)
@@ -49,18 +50,12 @@ end
49
50
  require 'hammer_cli'
50
51
 
51
52
  # load modules set in config
52
- modules = HammerCLI::Settings.get(:modules) || []
53
- modules.each do |m|
54
- begin
55
- require m
56
- rescue => e
57
- logger.error "Error while loading module #{m}"
58
- handler = HammerCLI::ExceptionHandler.new(:context => {}, :adapter => :base)
59
- handler.handle_exception(e)
60
- exit HammerCLI::EX_SOFTWARE
61
- end
62
- module_version = Gem.loaded_specs[m].version.to_s
63
- logger.info "Extension module #{m} (#{module_version}) loaded"
53
+ begin
54
+ HammerCLI::Modules.load_all
55
+ rescue => e
56
+ handler = HammerCLI::ExceptionHandler.new(:context => {}, :adapter => :base)
57
+ handler.handle_exception(e)
58
+ exit HammerCLI::EX_SOFTWARE
64
59
  end
65
60
 
66
61
  exit HammerCLI::MainCommand.run || HammerCLI::EX_OK
@@ -14,9 +14,8 @@ module HammerCLI
14
14
 
15
15
  option "--version", :flag, "show version" do
16
16
  puts "hammer (%s)" % HammerCLI.version
17
- modules = HammerCLI::Settings.get(:modules) || []
18
- modules.each do |m|
19
- module_version = Gem.loaded_specs[m].version.to_s
17
+ HammerCLI::Modules.names.each do |m|
18
+ module_version = HammerCLI::Modules.find_by_name(m).version
20
19
  puts " * #{m} (#{module_version})"
21
20
  end
22
21
  exit(HammerCLI::EX_OK)
@@ -0,0 +1,51 @@
1
+
2
+ module HammerCLI
3
+
4
+ class Modules
5
+
6
+ def self.names
7
+ HammerCLI::Settings.get(:modules) || []
8
+ end
9
+
10
+ def self.find_by_name(name)
11
+ possible_names = [
12
+ name.camelize,
13
+ name.camelize.gsub("Cli", "CLI")
14
+ ]
15
+
16
+ possible_names.each do |n|
17
+ return Object.const_get(n) if Object.const_defined?(n)
18
+ end
19
+ return nil
20
+ end
21
+
22
+ def self.load(name)
23
+ begin
24
+ require_module(name)
25
+ rescue Exception => e
26
+ logger.error "Error while loading module #{name}"
27
+ raise e
28
+ end
29
+
30
+ version = find_by_name(name).version
31
+ logger.info "Extension module #{name} (#{version}) loaded"
32
+ end
33
+
34
+ def self.require_module(name)
35
+ require name
36
+ end
37
+
38
+ def self.load_all
39
+ HammerCLI::Modules.names.each do |m|
40
+ Modules.load(m)
41
+ end
42
+ end
43
+
44
+ protected
45
+ def self.logger
46
+ Logging.logger['Modules']
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -15,4 +15,9 @@ class String
15
15
  end
16
16
  end
17
17
 
18
+ def camelize()
19
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
20
+ split('_').map{|e| e.capitalize}.join
21
+ end
22
+
18
23
  end
@@ -1,5 +1,5 @@
1
1
  module HammerCLI
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.0.13'
3
+ @version ||= Gem::Version.new '0.0.14'
4
4
  end
5
5
  end
data/lib/hammer_cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'hammer_cli/utils'
2
2
  require 'hammer_cli/version'
3
+ require 'hammer_cli/modules'
3
4
  require 'hammer_cli/exit_codes'
4
5
  require 'hammer_cli/settings'
5
6
  require 'hammer_cli/validator'
@@ -0,0 +1,82 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+
4
+ describe HammerCLI::Modules do
5
+
6
+ module HammerCLITom
7
+ def self.version
8
+ Gem::Version.new "0.0.1"
9
+ end
10
+ end
11
+
12
+ module HammerCliJerry
13
+ def self.version
14
+ Gem::Version.new "0.0.2"
15
+ end
16
+ end
17
+
18
+ before :each do
19
+ HammerCLI::Settings.clear
20
+ HammerCLI::Settings.load({
21
+ :modules => ["hammer_cli_tom", "hammer_cli_jerry"]
22
+ })
23
+
24
+ @log_output = Logging::Appenders['__test__']
25
+ @log_output.reset
26
+ end
27
+
28
+ describe "names" do
29
+ it "must return list of modules" do
30
+ HammerCLI::Modules.names.must_equal ["hammer_cli_tom", "hammer_cli_jerry"]
31
+ end
32
+
33
+ it "must return empty array by default" do
34
+ HammerCLI::Settings.clear
35
+ HammerCLI::Modules.names.must_equal []
36
+ end
37
+ end
38
+
39
+ describe "find by name" do
40
+ it "must return nil if the module does not exist" do
41
+ HammerCLI::Modules.find_by_name("hammer_cli_unknown").must_equal nil
42
+ end
43
+
44
+ it "must must find the module" do
45
+ HammerCLI::Modules.find_by_name("hammer_cli_jerry").must_equal HammerCliJerry
46
+ end
47
+
48
+ it "must find the module with capital CLI in it's name" do
49
+ HammerCLI::Modules.find_by_name("hammer_cli_tom").must_equal HammerCLITom
50
+ end
51
+ end
52
+
53
+ describe "load all modules" do
54
+
55
+ it "must call load for each module" do
56
+ HammerCLI::Modules.expects(:load).with("hammer_cli_tom")
57
+ HammerCLI::Modules.expects(:load).with("hammer_cli_jerry")
58
+ HammerCLI::Modules.load_all
59
+ end
60
+
61
+ end
62
+
63
+ describe "load a module" do
64
+ it "must require a module" do
65
+ HammerCLI::Modules.expects(:require_module).with("hammer_cli_tom")
66
+ HammerCLI::Modules.load("hammer_cli_tom")
67
+ end
68
+
69
+ it "must log module's name and version" do
70
+ HammerCLI::Modules.expects(:require_module).with("hammer_cli_tom")
71
+ HammerCLI::Modules.load("hammer_cli_tom")
72
+ @log_output.readline.strip.must_equal "INFO Modules : Extension module hammer_cli_tom (0.0.1) loaded"
73
+ end
74
+ end
75
+
76
+ it "must log an error if the load fails" do
77
+ proc { HammerCLI::Modules.load("hammer_cli_tom") }.must_raise LoadError
78
+ @log_output.readline.strip.must_equal "ERROR Modules : Error while loading module hammer_cli_tom"
79
+ end
80
+
81
+ end
82
+
@@ -31,5 +31,18 @@ describe String do
31
31
 
32
32
  end
33
33
 
34
+
35
+ context "camelize" do
36
+
37
+ it "should camelize string with underscores" do
38
+ "one_two_three".camelize.must_equal "OneTwoThree"
39
+ end
40
+
41
+ it "should not camelize string with dashes" do
42
+ "one-two-three".camelize.must_equal "One-two-three"
43
+ end
44
+
45
+ end
46
+
34
47
  end
35
48
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Bačovský
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-18 00:00:00.000000000 Z
12
+ date: 2013-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clamp
@@ -154,6 +154,7 @@ files:
154
154
  - lib/hammer_cli/exception_handler.rb
155
155
  - lib/hammer_cli/output.rb
156
156
  - lib/hammer_cli/shell.rb
157
+ - lib/hammer_cli/modules.rb
157
158
  - lib/hammer_cli/utils.rb
158
159
  - lib/hammer_cli/output/adapter/table.rb
159
160
  - lib/hammer_cli/output/adapter/base.rb
@@ -185,6 +186,7 @@ files:
185
186
  - test/unit/exception_handler_test.rb
186
187
  - test/unit/main_test.rb
187
188
  - test/unit/test_helper.rb
189
+ - test/unit/modules_test.rb
188
190
  - test/unit/abstract_test.rb
189
191
  - test/unit/output/adapter/base_test.rb
190
192
  - test/unit/output/adapter/csv_test.rb
@@ -246,6 +248,7 @@ test_files:
246
248
  - test/unit/exception_handler_test.rb
247
249
  - test/unit/main_test.rb
248
250
  - test/unit/test_helper.rb
251
+ - test/unit/modules_test.rb
249
252
  - test/unit/abstract_test.rb
250
253
  - test/unit/output/adapter/base_test.rb
251
254
  - test/unit/output/adapter/csv_test.rb