simonmenke-gm 0.1.4 → 0.1.6

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,16 +7,19 @@ class BuildCommand < GM::Command
7
7
  build a gem and put the result in pkg/
8
8
  DOC
9
9
 
10
+ def add_options(p)
11
+ p.flag 'E', 'no-emulation', :desc => 'Don\'t emulate any network'
12
+ end
13
+
10
14
  def run
11
- app.emulate = true
12
- GM::Command.run(:build_gemspec)
15
+ GM::Command.run(:build_gemspec, [(options.no_emulation? ? '-E' : nil)].compact)
13
16
 
14
17
  app.info "Building your gem..."
15
- builder = Gem::Builder.new app.gemspec
16
- app.gem_file_name = builder.build
17
- 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}",
18
21
  "mkdir -p pkg",
19
- "mv #{app.gem_file_name} pkg/")
22
+ "mv #{gem_file_name} pkg/")
20
23
  end
21
24
 
22
25
  end
@@ -1,12 +1,16 @@
1
1
 
2
2
  class BuildGemspecCommand < GM::Command
3
3
 
4
+ def add_options(p)
5
+ p.flag 'E', 'no-emulation', :desc => 'Don\'t emulate any network'
6
+ end
7
+
4
8
  def run
5
9
  app.info "Generating your gemspec..."
6
- app.gemspec = Gem::Specification.new
7
10
 
8
11
  GM::Behavior.behaviors.each do |name,klass|
9
12
  behavior = klass.new
13
+ behavior.command = self
10
14
  behavior.run
11
15
  end
12
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
@@ -11,8 +11,80 @@ class RubyforgeNetwork < GM::Network
11
11
  s.should_not_be_empty
12
12
  end
13
13
 
14
+ rubyforge.conf(:package) do |s|
15
+ s.should_be_a String
16
+ s.should_not_be_empty
17
+ end
18
+
14
19
  end
15
20
 
16
21
  end
17
22
 
23
+ def publish
24
+ prepare
25
+ version = config[:general][:version]
26
+ GM::Command.run(:build, ['-E'])
27
+ sh "rubyforge add_release #{group_id} #{package_id} #{version} pkg/#{gem_file_name}"
28
+ end
29
+
30
+ def published_versions
31
+ prepare
32
+ if rubyforge_info['release_ids'][package_name]
33
+ rubyforge_info['release_ids'][package_name].keys
34
+ else
35
+ []
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def rubyforge_info(reset=false)
42
+ @rubyforge_info = nil if reset
43
+ @rubyforge_info ||= YAML.load_file(File.expand_path('~/.rubyforge/auto-config.yml'))
44
+ end
45
+
46
+ def project_name
47
+ if config[:rubyforge]
48
+ config[:rubyforge][:project]
49
+ else
50
+ config[:general][:name]
51
+ end
52
+ end
53
+
54
+ def package_name
55
+ if config[:rubyforge] and config[:rubyforge][:package]
56
+ config[:rubyforge][:package]
57
+ else
58
+ config[:general][:name]
59
+ end
60
+ end
61
+
62
+ def group_id
63
+ @group_id ||= rubyforge_info['group_ids'][project_name]
64
+ end
65
+
66
+ def package_id
67
+ @package_id ||= rubyforge_info['package_ids'][package_name]
68
+ end
69
+
70
+ def prepare
71
+ unless @prepared
72
+ login
73
+ create_package
74
+ @prepared = true
75
+ end
76
+ end
77
+
78
+ def login
79
+ sh "rubyforge login",
80
+ "rubyforge config"
81
+ end
82
+
83
+ def create_package
84
+ unless rubyforge_info['package_ids'].include? package_name
85
+ sh "rubyforge create_package #{group_id} #{package_name}"
86
+ rubyforge_info(true)
87
+ end
88
+ end
89
+
18
90
  end
data/lib/gm/app.rb CHANGED
@@ -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
data/lib/gm/behavior.rb CHANGED
@@ -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
data/lib/gm/command.rb CHANGED
@@ -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.
data/lib/gm/helpers.rb CHANGED
@@ -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
data/test/command_test.rb CHANGED
@@ -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: simonmenke-gm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -19,7 +19,34 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.0.3
22
+ version: 0.0.4
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: clip
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.0.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: rubigen
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.1
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: simonmenke-ec
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.4
23
50
  version:
24
51
  - !ruby/object:Gem::Dependency
25
52
  name: clip
@@ -49,6 +76,14 @@ extensions: []
49
76
  extra_rdoc_files: []
50
77
 
51
78
  files:
79
+ - test/command_test.rb
80
+ - test/gem_extentions_test.rb
81
+ - test/system_test.rb
82
+ - test/test_helper.rb
83
+ - bin/gem-make
84
+ - bin/gm
85
+ - LICENSE.txt
86
+ - README.textile
52
87
  - gm_generators/bin/bin_generator.rb
53
88
  - gm_generators/bin/templates/bin/bin.rb
54
89
  - gm_generators/gem/gem_generator.rb
@@ -102,14 +137,6 @@ files:
102
137
  - gm_generators/rails/templates/rails
103
138
  - gm_generators/test
104
139
  - gm_generators/test/templates
105
- - test/command_test.rb
106
- - test/gem_extentions_test.rb
107
- - test/system_test.rb
108
- - test/test_helper.rb
109
- - bin/gem-make
110
- - bin/gm
111
- - LICENSE.txt
112
- - README.textile
113
140
  - lib/autotest/discover.rb
114
141
  - lib/autotest/gm.rb
115
142
  - lib/extentions/gem.rb
@@ -144,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
171
  version:
145
172
  requirements: []
146
173
 
147
- rubyforge_project: gm
174
+ rubyforge_project: gem-make
148
175
  rubygems_version: 1.2.0
149
176
  signing_key:
150
177
  specification_version: 2
@@ -154,3 +181,7 @@ test_files:
154
181
  - test/gem_extentions_test.rb
155
182
  - test/system_test.rb
156
183
  - test/test_helper.rb
184
+ - test/command_test.rb
185
+ - test/gem_extentions_test.rb
186
+ - test/system_test.rb
187
+ - test/test_helper.rb