gm 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,10 @@
2
2
  class GithubBehavior < GM::Behavior
3
3
 
4
4
  def run
5
- if GM::App.emulate? and config[:github][:emulate]
5
+ emulate = !command.options.no_emulation?
6
+ emulate &= (config[:github] != nil) && (config[:github][:emulate] == true)
7
+
8
+ if emulate
6
9
  name = config[:github][:project] || config[:general][:name]
7
10
  spec.name = "#{config[:github][:username]}-#{name}"
8
11
  end
@@ -7,7 +7,7 @@ class BuildCommand < GM::Command
7
7
  build a gem and put the result in pkg/
8
8
  DOC
9
9
 
10
- def extra_options(p)
10
+ def add_options(p)
11
11
  p.flag 'E', 'no-emulation', :desc => 'Don\'t emulate any network'
12
12
  end
13
13
 
@@ -15,11 +15,11 @@ class BuildCommand < GM::Command
15
15
  GM::Command.run(:build_gemspec, [(options.no_emulation? ? '-E' : nil)].compact)
16
16
 
17
17
  app.info "Building your gem..."
18
- builder = Gem::Builder.new app.gemspec
19
- app.gem_file_name = builder.build
20
- sh("rm -f pkg/#{app.gem_file_name}",
18
+ builder = Gem::Builder.new app.spec
19
+ builder.build
20
+ sh("rm -f pkg/#{gem_file_name}",
21
21
  "mkdir -p pkg",
22
- "mv #{app.gem_file_name} pkg/")
22
+ "mv #{gem_file_name} pkg/")
23
23
  end
24
24
 
25
25
  end
@@ -1,17 +1,16 @@
1
1
 
2
2
  class BuildGemspecCommand < GM::Command
3
3
 
4
- def extra_options(p)
4
+ def add_options(p)
5
5
  p.flag 'E', 'no-emulation', :desc => 'Don\'t emulate any network'
6
6
  end
7
7
 
8
8
  def run
9
9
  app.info "Generating your gemspec..."
10
- app.emulate = !options.no_emulation?
11
- app.gemspec = Gem::Specification.new
12
10
 
13
11
  GM::Behavior.behaviors.each do |name,klass|
14
12
  behavior = klass.new
13
+ behavior.command = self
15
14
  behavior.run
16
15
  end
17
16
 
@@ -35,7 +35,7 @@ EOC
35
35
  end
36
36
 
37
37
  def run_show
38
- GM::Command.run(:build_gemspec)
38
+ GM::Command.run(:build_gemspec, ['-E'])
39
39
  puts config.to_yaml
40
40
  end
41
41
 
@@ -20,7 +20,7 @@ class GenCommand < GM::Command
20
20
  DOC
21
21
 
22
22
  def run
23
- GM::Command.run(:build_gemspec) if File.exist?('./Gmfile')
23
+ GM::Command.run(:build_gemspec, ['-E']) if File.exist?('./Gmfile')
24
24
  @gen_name = self.argv.shift
25
25
  @gen_options = self.argv
26
26
 
@@ -135,7 +135,7 @@ class HelpCommand < GM::Command
135
135
  def doc_command(command)
136
136
  options = Clip { |p|
137
137
  p.banner = command.banner_text
138
- command.new.extra_options(p)
138
+ command.new.options(p)
139
139
  }.to_s
140
140
  options.gsub!(/Usage:\n/, '')
141
141
  %{
@@ -11,7 +11,7 @@ class InstallCommand < GM::Command
11
11
  GM::Command.run(:build)
12
12
 
13
13
  app.info "Installing your gem..."
14
- sh("sudo gem install pkg/#{app.gem_file_name}")
14
+ sh("sudo gem install pkg/#{gem_file_name}")
15
15
  end
16
16
 
17
17
  end
@@ -11,9 +11,10 @@ class PublishCommand < GM::Command
11
11
  DOC
12
12
 
13
13
  def run
14
- GM::Command.run(:build_gemspec)
15
14
 
16
15
  networks = argv.collect do |network|
16
+ app.reset_spec!
17
+ GM::Command.run(:build_gemspec, ['-E'])
17
18
  name = network.underscore.to_sym
18
19
  klass = GM::Network.networks[name]
19
20
  klass.new unless klass.nil?
@@ -4,10 +4,10 @@ class SpecCommand < GM::Command
4
4
  desc "Dump the gemspec file."
5
5
 
6
6
  def run
7
- GM::Command.run(:build_gemspec)
7
+ GM::Command.run(:build_gemspec, ['-E'])
8
8
  app.info "Writing your gemspec..."
9
- File.open("#{app.gemspec.name}.gemspec", 'w+') do |f|
10
- f.write app.gemspec.to_ruby
9
+ File.open("#{app.spec.name}.gemspec", 'w+') do |f|
10
+ f.write app.spec.to_ruby
11
11
  end
12
12
  end
13
13
 
@@ -61,7 +61,7 @@ class GithubNetwork < GM::Network
61
61
  def commit_gemspec
62
62
  version = config[:general][:version]
63
63
  GM::Command.run(:spec)
64
- sh %{ git ci -m "Bumped to version #{version}" -o "#{app.gemspec.name}.gemspec" -o "Gmfile" }
64
+ sh %{ git ci -m "Bumped to version #{version}" -o "#{app.spec.name}.gemspec" -o "Gmfile" }
65
65
  end
66
66
 
67
67
  def push_to_github
@@ -24,7 +24,7 @@ class RubyforgeNetwork < GM::Network
24
24
  prepare
25
25
  version = config[:general][:version]
26
26
  GM::Command.run(:build, ['-E'])
27
- sh "rubyforge add_release #{group_id} #{package_id} #{version} pkg/#{app.gem_file_name}"
27
+ sh "rubyforge add_release #{group_id} #{package_id} #{version} pkg/#{gem_file_name}"
28
28
  end
29
29
 
30
30
  def published_versions
@@ -4,33 +4,23 @@ module GM
4
4
  class App
5
5
  include Singleton
6
6
 
7
- attr_accessor :configuration_passes
8
- attr_accessor :gemspec
9
- attr_accessor :emulate
10
- attr_accessor :gem_file_name
11
- attr_accessor :log_level
12
-
13
7
  def initialize # :nodoc:
14
- @log_level = :normal
15
8
  reset!
16
9
  end
17
10
 
18
11
  # reset the app
19
12
  def reset!
20
- @configuration_passes = Hash.new { |h, k| h[k] = {} }
13
+ EC.store.reset!(true)
14
+ GM::Behavior.behaviors.clear
21
15
  GM::Command.commands.clear
22
16
  GM::Network.networks.clear
23
- end
24
-
25
- # exclude a pass from the configuration fase
26
- def exclude_pass(name, fase=:normal)
27
- @configuration_passes[fase.to_sym].delete(name.to_sym)
28
- end
29
-
30
- # extra options provided by the app.
31
- def extra_options(options)
32
- options.flag 'v', 'verbose', :desc => 'Print more information.'
33
- options.flag 'd', 'debug', :desc => 'Print debugging information.'
17
+
18
+ EC.store.specify do |root|
19
+ root.conf(:log_level) do |c|
20
+ c.should_be_a String
21
+ c.should_not_be_empty
22
+ end
23
+ end
34
24
  end
35
25
 
36
26
  # run the app
@@ -39,6 +29,16 @@ module GM
39
29
  load_commands
40
30
  load_networks
41
31
 
32
+ if ARGV.include? '-v'
33
+ EC.store.config[:log_level] = 'verbose'
34
+ ARGV.delete '-v'
35
+ elsif ARGV.include? '-d'
36
+ EC.store.config[:log_level] = 'debug'
37
+ ARGV.delete '-d'
38
+ else
39
+ EC.store.config[:log_level] = 'normal'
40
+ end
41
+
42
42
  load_configuration('~/.gmrc')
43
43
  load_configuration('Gmfile')
44
44
  EC.store.validate
@@ -55,21 +55,24 @@ module GM
55
55
  end
56
56
  end
57
57
 
58
- # should we emulate github?
59
- def self.emulate?
60
- instance.emulate || false
58
+ def reset_spec!
59
+ @spec = nil
60
+ end
61
+
62
+ def spec
63
+ @spec ||= Gem::Specification.new
61
64
  end
62
65
 
63
66
  def log(msg)
64
- puts msg
67
+ puts msg if %w( debug verbose normal ).include? EC.store.config[:log_level]
65
68
  end
66
69
 
67
70
  def info(msg)
68
- puts msg if log_level == :verbose
71
+ puts msg if %w( debug verbose ).include? EC.store.config[:log_level]
69
72
  end
70
73
 
71
74
  def debug(msg)
72
- puts msg if log_level == :verbose or log_level == :debug
75
+ puts msg if %w( debug ).include? EC.store.config[:log_level]
73
76
  end
74
77
 
75
78
  private
@@ -14,6 +14,8 @@ module GM
14
14
 
15
15
  loads :behaviors
16
16
 
17
+ attr_accessor :command
18
+
17
19
  def run
18
20
 
19
21
  end
@@ -19,7 +19,6 @@ module GM
19
19
 
20
20
  # build a command
21
21
  def self.run(cmd_name=nil, argv=ARGV)
22
- app = GM.app
23
22
  if Array === cmd_name
24
23
  argv = cmd_name
25
24
  cmd_name = nil
@@ -27,11 +26,8 @@ module GM
27
26
  cmd = self.build(cmd_name, argv)
28
27
  clip = Clip(argv) do |p|
29
28
  p.banner = cmd.banner_text
30
- app.extra_options(p)
31
- cmd.extra_options(p)
29
+ cmd.add_options(p)
32
30
  end
33
- app.log_level = :verbose if clip.verbose?
34
- app.log_level = :debug if clip.debug?
35
31
  cmd.options = clip
36
32
  argv.clear
37
33
  argv.concat(clip.remainder)
@@ -58,7 +54,7 @@ module GM
58
54
  end
59
55
 
60
56
  # A command can overwrite this method in order to add extra command line options.
61
- def extra_options(options)
57
+ def add_options(options)
62
58
  end
63
59
 
64
60
  # A command must overwrite this method.
@@ -12,7 +12,11 @@ module GM
12
12
  end
13
13
 
14
14
  def spec
15
- GM.app.gemspec
15
+ GM.app.spec
16
+ end
17
+
18
+ def gem_file_name
19
+ "#{spec.name}-#{spec.version}.gem"
16
20
  end
17
21
 
18
22
  end
@@ -69,8 +69,8 @@ class CommandTest < Test::Unit::TestCase
69
69
  hello_cmd = mock('hello_command') do
70
70
  expects(:run)
71
71
  expects(:banner_text).returns("")
72
- expects(:extra_options).with() { |value| Clip::Parser === value }
73
- expects(:options=).with() { |value| Clip::Parser === value }
72
+ expects(:add_options).with() { |value| Clip::Parser === value }
73
+ expects(:options=).with() { |value| Clip::Parser === value }
74
74
  expects(:argv=).with %w( p )
75
75
  end
76
76
  hello_cmd_class = mock('hello_command_class') do
@@ -85,8 +85,8 @@ class CommandTest < Test::Unit::TestCase
85
85
  hello_cmd = mock('hello_command') do
86
86
  expects(:run)
87
87
  expects(:banner_text).returns("")
88
- expects(:extra_options).with() { |value| Clip::Parser === value }
89
- expects(:options=).with() { |value| Clip::Parser === value }
88
+ expects(:add_options).with() { |value| Clip::Parser === value }
89
+ expects(:options=).with() { |value| Clip::Parser === value }
90
90
  expects(:argv=).with %w( p )
91
91
  end
92
92
  hello_cmd_class = mock('hello_command_class') do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -20,7 +20,37 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.0.3
23
+ version: 0.0.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: clip
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rubigen
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.1
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: simonmenke-ec
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.0.4
24
54
  version:
25
55
  - !ruby/object:Gem::Dependency
26
56
  name: clip
@@ -52,6 +82,14 @@ extensions: []
52
82
  extra_rdoc_files: []
53
83
 
54
84
  files:
85
+ - test/command_test.rb
86
+ - test/gem_extentions_test.rb
87
+ - test/system_test.rb
88
+ - test/test_helper.rb
89
+ - bin/gem-make
90
+ - bin/gm
91
+ - LICENSE.txt
92
+ - README.textile
55
93
  - gm_generators/bin/bin_generator.rb
56
94
  - gm_generators/bin/templates/bin/bin.rb
57
95
  - gm_generators/gem/gem_generator.rb
@@ -105,14 +143,6 @@ files:
105
143
  - gm_generators/rails/templates/rails
106
144
  - gm_generators/test
107
145
  - gm_generators/test/templates
108
- - test/command_test.rb
109
- - test/gem_extentions_test.rb
110
- - test/system_test.rb
111
- - test/test_helper.rb
112
- - bin/gem-make
113
- - bin/gm
114
- - LICENSE.txt
115
- - README.textile
116
146
  - lib/autotest/discover.rb
117
147
  - lib/autotest/gm.rb
118
148
  - lib/extentions/gem.rb
@@ -157,3 +187,7 @@ test_files:
157
187
  - test/gem_extentions_test.rb
158
188
  - test/system_test.rb
159
189
  - test/test_helper.rb
190
+ - test/command_test.rb
191
+ - test/gem_extentions_test.rb
192
+ - test/system_test.rb
193
+ - test/test_helper.rb