penchant 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/penchant CHANGED
@@ -63,6 +63,22 @@ class PenchantCLI < Thor
63
63
  puts get_current_env
64
64
  end
65
65
 
66
+ desc "bootstrap [DIR = ..]", "Download all referred-to git repos to the specified directory"
67
+ def bootstrap(dir = '..')
68
+ Penchant::Gemfile.defined_git_repos.each do |repo|
69
+ puts "Cloning #{repo} to #{dir}."
70
+ repo.clone_to(dir)
71
+ end
72
+ end
73
+
74
+ def method_missing(method, *args)
75
+ if Penchant::Gemfile.available_environments.include?(method)
76
+ gemfile(method, *args)
77
+ else
78
+ super(method, *args)
79
+ end
80
+ end
81
+
66
82
  no_tasks do
67
83
  def get_current_env
68
84
  gemfile = Penchant::Gemfile.new
@@ -32,6 +32,19 @@ Feature: Gemfiles
32
32
  this is content
33
33
  """
34
34
 
35
+ Scenario: Simple env
36
+ Given I have the file "Gemfile.erb" with the content:
37
+ """
38
+ <% env :local do %>
39
+ gem 'test'
40
+ <% end %>
41
+ """
42
+ When I rebuild the Gemfile for "local" mode
43
+ Then the file "Gemfile" should have the following stripped content:
44
+ """
45
+ # generated by penchant, environment: local
46
+ gem 'test'
47
+ """
35
48
  Scenario: Use placeholder expansion
36
49
  Given I have the file "Gemfile.erb" with the content:
37
50
  """
@@ -40,10 +53,11 @@ Feature: Gemfiles
40
53
  <% end %>
41
54
  """
42
55
  When I rebuild the Gemfile for "local" mode
56
+
43
57
  Then the file "Gemfile" should have the following stripped content:
44
58
  """
45
59
  # generated by penchant, environment: local
46
- gem 'test', :path => %{../test}
60
+ gem 'test', {:path=>"../test"}
47
61
  """
48
62
 
49
63
  Scenario: Use a gem list for an operation
@@ -59,7 +73,7 @@ Feature: Gemfiles
59
73
  Then the file "Gemfile" should have the following stripped content:
60
74
  """
61
75
  # generated by penchant, environment: local
62
- gem 'test', :path => %{../test}
76
+ gem 'test', {:path=>"../test"}
63
77
  """
64
78
 
65
79
  Scenario: Let gem get additional info
@@ -1,10 +1,13 @@
1
1
  @fakefs
2
2
  Feature: Gemfiles
3
+ @wip
3
4
  Scenario: Process a pure Ruby gemfile
4
5
  Given I have the file "Gemfile.penchant" with the content:
5
6
  """
6
7
  source :rubygems
7
8
 
9
+ gemspec
10
+
8
11
  group :cats, :dogs do
9
12
  case environment
10
13
  when :local
@@ -19,6 +22,7 @@ Feature: Gemfiles
19
22
  """
20
23
  # generated by penchant, environment: local
21
24
  source :rubygems
25
+ gemspec
22
26
 
23
27
  group :cats, :dogs do
24
28
  gem "test", {:path=>"../test"}
@@ -29,6 +33,7 @@ Feature: Gemfiles
29
33
  """
30
34
  # generated by penchant, environment: remote
31
35
  source :rubygems
36
+ gemspec
32
37
 
33
38
  group :cats, :dogs do
34
39
  gem "test", {:git=>"git://github.com/johnbintz/test.git"}
@@ -129,7 +134,7 @@ Feature: Gemfiles
129
134
  gem "one", {:path=>"../one"}
130
135
  """
131
136
 
132
- @wip @mocha
137
+ @mocha
133
138
  Scenario: OS-specific blocks
134
139
  Given I have the file "Gemfile.penchant" with the content:
135
140
  """
@@ -152,3 +157,29 @@ Feature: Gemfiles
152
157
 
153
158
  """
154
159
 
160
+ Scenario: Get the list of environments defined
161
+ Given I have the file "Gemfile.penchant" with the content:
162
+ """
163
+ env :cat do
164
+ gem 'one', :path => '../%s'
165
+ end
166
+
167
+ env :dog do
168
+ gem 'two', :path => '../%s'
169
+ end
170
+ """
171
+ When I request the list of environments available
172
+ Then I should get the following environments:
173
+ | cat |
174
+ | dog |
175
+
176
+ Scenario: Get the list of git repos defined
177
+ Given I have the file "Gemfile.penchant" with the content:
178
+ """
179
+ gem 'one', :path => '../%s'
180
+ gem 'two', :git => 'git://github.cats/%s.git'
181
+ """
182
+ When I request the list of git repositories
183
+ Then I should get the following repositories:
184
+ | git://github.cats/two.git |
185
+
@@ -0,0 +1,3 @@
1
+ Then /^I should get the following environments:$/ do |table|
2
+ @environments.collect(&:to_s).sort.should == table.raw.flatten.sort
3
+ end
@@ -0,0 +1,4 @@
1
+ Then /^I should get the following repositories:$/ do |table|
2
+ @repos.collect(&:to_s).sort.should == table.raw.flatten.sort
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ When /^I request the list of environments available$/ do
2
+ @environments = Penchant::Gemfile.available_environments
3
+ end
@@ -0,0 +1,3 @@
1
+ When /^I request the list of git repositories$/ do
2
+ @repos = Penchant::Gemfile.defined_git_repos
3
+ end
@@ -17,17 +17,26 @@ module Penchant
17
17
  end
18
18
 
19
19
  def self.pre_switch(env, deployment = false)
20
- gemfile = Penchant::Gemfile.new
20
+ gemfile = new
21
21
  return false if !gemfile.has_processable_gemfile?
22
22
  gemfile.run_dot_penchant!(env, deployment)
23
23
 
24
24
  gemfile
25
25
  end
26
26
 
27
+ def self.available_environments
28
+ new.available_environments
29
+ end
30
+
31
+ def self.defined_git_repos
32
+ new.defined_git_repos
33
+ end
34
+
27
35
  def current_env ; @env ; end
28
36
 
29
37
  def initialize(path = Dir.pwd)
30
38
  @path = path
39
+ @env = environment
31
40
  end
32
41
 
33
42
  def gemfile_path
@@ -75,7 +84,7 @@ module Penchant
75
84
  end
76
85
 
77
86
  class FileProcessor
78
- attr_reader :environment, :is_deployment
87
+ attr_reader :environment, :is_deployment, :available_environments, :defined_git_repos
79
88
 
80
89
  def self.result(data, *args)
81
90
  new(data).result(*args)
@@ -91,6 +100,8 @@ module Penchant
91
100
 
92
101
  def initialize(data)
93
102
  @data = data
103
+ @available_environments = []
104
+ @defined_git_repos = []
94
105
  end
95
106
 
96
107
  def result(_env, _is_deployment)
@@ -105,6 +116,8 @@ module Penchant
105
116
  end
106
117
 
107
118
  def env(*args)
119
+ @available_environments += args
120
+
108
121
  yield if args.include?(environment)
109
122
  end
110
123
 
@@ -168,14 +181,20 @@ module Penchant
168
181
  end
169
182
 
170
183
  def env(check, template = {}, &block)
171
- if check.to_s == @env.to_s
184
+ if check.to_s == @environment.to_s
172
185
  original_erbout = @_erbout.dup
173
186
 
174
187
  output = instance_eval(&block).lines.to_a
175
188
 
176
189
  output.each do |line|
177
190
  if gem_name = line[%r{gem ['"]([^'"]+)['"]}, 1]
178
- line.replace(line.rstrip + process_options(gem_name, template) + "\n")
191
+ new_line = line.rstrip
192
+
193
+ if !(options = process_options(gem_name, template)).empty?
194
+ new_line += ", #{options.inspect}"
195
+ end
196
+
197
+ line.replace(new_line + "\n")
179
198
  end
180
199
  end
181
200
 
@@ -220,9 +239,17 @@ module Penchant
220
239
  args = [ gem_name.first ]
221
240
  args << options if !options.empty?
222
241
 
242
+ if options[:git]
243
+ @defined_git_repos << Penchant::Repo.new(options[:git])
244
+ end
245
+
223
246
  @output << %{gem #{args_to_string(args)}}
224
247
  end
225
248
 
249
+ def gemspec
250
+ @output << %{gemspec}
251
+ end
252
+
226
253
  def gems(*args)
227
254
  gems, template = split_args(args)
228
255
 
@@ -250,10 +277,20 @@ module Penchant
250
277
  end
251
278
  end
252
279
 
280
+ def available_environments
281
+ process
282
+ builder.available_environments
283
+ end
284
+
285
+ def defined_git_repos
286
+ process
287
+ builder.defined_git_repos
288
+ end
289
+
253
290
  def switch_to!(gemfile_env = nil, deployment = false)
254
291
  @env, @is_deployment = gemfile_env, deployment
255
292
 
256
- output = [ header, process(template) ]
293
+ output = [ header, process ]
257
294
 
258
295
  File.open(gemfile_path, 'wb') { |fh| fh.print output.join("\n") }
259
296
  end
@@ -285,15 +322,21 @@ module Penchant
285
322
  File.join(@path, file)
286
323
  end
287
324
 
288
- def process(template)
289
- builder = case File.extname(processable_gemfile_path)
325
+ def process
326
+ builder.result(@env, @is_deployment)
327
+ end
328
+
329
+ def builder
330
+ return @builder if @builder
331
+
332
+ klass = case File.extname(processable_gemfile_path)
290
333
  when '.penchant'
291
334
  PenchantFile
292
335
  when '.erb'
293
336
  ERBFile
294
337
  end
295
338
 
296
- builder.result(template, @env, @is_deployment)
339
+ @builder = klass.new(template)
297
340
  end
298
341
 
299
342
  def template
@@ -0,0 +1,16 @@
1
+ module Penchant
2
+ class Repo
3
+ def initialize(url)
4
+ @url = url
5
+ end
6
+
7
+ def clone_to(dir)
8
+ Dir.chdir(dir) do
9
+ system %{git clone #{@url}}
10
+ end
11
+ end
12
+
13
+ def to_s ; @url ; end
14
+ end
15
+ end
16
+
@@ -1,3 +1,3 @@
1
1
  module Penchant
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/penchant.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Penchant
2
2
  autoload :Gemfile, 'penchant/gemfile'
3
+ autoload :Repo, 'penchant/repo'
3
4
  autoload :DotPenchant, 'penchant/dot_penchant'
4
5
  end
@@ -150,7 +150,7 @@ ERB
150
150
  end
151
151
 
152
152
  describe '#switch_to!' do
153
- let(:template) { 'template' }
153
+ let(:template) { 'source' }
154
154
  let(:gemfile_path) { 'gemfile path' }
155
155
  let(:header) { 'header' }
156
156
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: penchant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
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-06-06 00:00:00.000000000 Z
12
+ date: 2012-06-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Things I do for my Rails projects to get up to speed in new environments
15
15
  fast
@@ -32,18 +32,23 @@ files:
32
32
  - features/ruby_gemfile.feature
33
33
  - features/step_definitions/given/i_am_on_the_linux_platform.rb
34
34
  - features/step_definitions/given/i_have_the_file_with_content.rb
35
+ - features/step_definitions/then/i_should_get_the_following_environments.rb
36
+ - features/step_definitions/then/i_should_get_the_following_repositories.rb
35
37
  - features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb
36
38
  - features/step_definitions/then/the_file_should_have_content.rb
37
39
  - features/step_definitions/then/the_output_should_include.rb
38
40
  - features/step_definitions/when/i_rebuild_the_gemfile_for_local_mode.rb
39
41
  - features/step_definitions/when/i_rebuild_the_gemfile_switching_back.rb
40
42
  - features/step_definitions/when/i_rebuild_the_gemfile_with_deployment.rb
43
+ - features/step_definitions/when/i_request_the_list_of_environments_available.rb
44
+ - features/step_definitions/when/i_request_the_list_of_git_repositories.rb
41
45
  - features/step_definitions/when/i_run_in.rb
42
46
  - features/support/cuke-pack.rb
43
47
  - features/support/env.rb
44
48
  - lib/penchant.rb
45
49
  - lib/penchant/dot_penchant.rb
46
50
  - lib/penchant/gemfile.rb
51
+ - lib/penchant/repo.rb
47
52
  - lib/penchant/version.rb
48
53
  - penchant.gemspec
49
54
  - script/gemfile
@@ -93,12 +98,16 @@ test_files:
93
98
  - features/ruby_gemfile.feature
94
99
  - features/step_definitions/given/i_am_on_the_linux_platform.rb
95
100
  - features/step_definitions/given/i_have_the_file_with_content.rb
101
+ - features/step_definitions/then/i_should_get_the_following_environments.rb
102
+ - features/step_definitions/then/i_should_get_the_following_repositories.rb
96
103
  - features/step_definitions/then/the_file_gemfile_should_have_the_following_stripped_content.rb
97
104
  - features/step_definitions/then/the_file_should_have_content.rb
98
105
  - features/step_definitions/then/the_output_should_include.rb
99
106
  - features/step_definitions/when/i_rebuild_the_gemfile_for_local_mode.rb
100
107
  - features/step_definitions/when/i_rebuild_the_gemfile_switching_back.rb
101
108
  - features/step_definitions/when/i_rebuild_the_gemfile_with_deployment.rb
109
+ - features/step_definitions/when/i_request_the_list_of_environments_available.rb
110
+ - features/step_definitions/when/i_request_the_list_of_git_repositories.rb
102
111
  - features/step_definitions/when/i_run_in.rb
103
112
  - features/support/cuke-pack.rb
104
113
  - features/support/env.rb