penchant 0.2.24 → 0.2.26

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.
@@ -12,12 +12,9 @@ module Penchant
12
12
  return false if !File.symlink?(target)
13
13
  return false if !File.expand_path(File.readlink(target)) == File.expand_path(file)
14
14
  end
15
-
16
- true
17
- else
18
- # no script/hooks dir, so we must not want them
19
- true
20
15
  end
16
+
17
+ true
21
18
  end
22
19
 
23
20
  def self.install!
@@ -0,0 +1,28 @@
1
+ module Penchant
2
+ class PropertyStack
3
+ PATHING_OPTIONS = [ :git, :branch, :path ].freeze
4
+
5
+ def initialize(builder, property_stack, strip_pathing_options)
6
+ @builder, @property_stack, @strip_pathing_options = builder, property_stack.dup, strip_pathing_options
7
+ end
8
+
9
+ def processor
10
+ @processor ||= PropertyStackProcessor.new(@builder)
11
+ end
12
+
13
+ def process_for_gem(gem_name, additional_env = {})
14
+ properties = processor.process(gem_name, @property_stack)
15
+
16
+ if @strip_pathing_options
17
+ PATHING_OPTIONS.each { |key| properties.delete(key) }
18
+ end
19
+
20
+ properties = processor.process(gem_name, @builder.defaults[gem_name].merge(additional_env)).merge(properties)
21
+
22
+ properties.delete(:opposite)
23
+
24
+ Hash[properties.sort]
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,24 @@
1
+ module Penchant
2
+ class PropertyStackBuilder
3
+ attr_reader :defaults
4
+
5
+ def initialize(defaults)
6
+ @defaults = defaults
7
+
8
+ @custom_properties = {}
9
+ end
10
+
11
+ def []=(key, value)
12
+ @custom_properties[key] = CustomProperty.new(value)
13
+ end
14
+
15
+ def [](key)
16
+ @custom_properties[key]
17
+ end
18
+
19
+ def create_stack_for(stack, strip_pathing_options = false)
20
+ PropertyStack.new(self, stack, strip_pathing_options)
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,26 @@
1
+ module Penchant
2
+ class PropertyStackProcessor
3
+ def initialize(builder)
4
+ @builder = builder
5
+ end
6
+
7
+ def process(gem_name, stack)
8
+ properties = {}
9
+ property_stack = stack.dup.to_a
10
+
11
+ while !property_stack.empty?
12
+ key, value = property_stack.shift
13
+
14
+ if property = @builder[key]
15
+ property_stack += property.process([ value ].flatten)
16
+ else
17
+ value = value % gem_name if value.respond_to?(:%)
18
+
19
+ properties[key] = value
20
+ end
21
+ end
22
+
23
+ properties
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Penchant
2
- VERSION = "0.2.24"
2
+ VERSION = "0.2.26"
3
3
  end
data/lib/penchant.rb CHANGED
@@ -3,4 +3,11 @@ module Penchant
3
3
  autoload :Repo, 'penchant/repo'
4
4
  autoload :DotPenchant, 'penchant/dot_penchant'
5
5
  autoload :Hooks, 'penchant/hooks'
6
+ autoload :Env, 'penchant/env'
7
+ autoload :FileProcessor, 'penchant/file_processor'
8
+ autoload :Defaults, 'penchant/defaults'
9
+ autoload :CustomProperty, 'penchant/custom_property'
10
+ autoload :PropertyStack, 'penchant/property_stack'
11
+ autoload :PropertyStackBuilder, 'penchant/property_stack_builder'
12
+ autoload :PropertyStackProcessor, 'penchant/property_stack_processor'
6
13
  end
@@ -1,23 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if File.file?('Gemfile.erb')
4
- pwd = Dir.pwd
5
-
6
- Dir.chdir '..' do
7
- File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
8
- repo = line[%r{:git => (['"])([^'"]+)\1}, 2]
9
-
10
- puts "Installing #{repo}"
11
- system %{git clone #{repo}}
12
- end
13
- end
14
-
15
- puts "Bundling for local environment"
16
- system %{script/gemfile local}
17
- else
18
- puts "Bundling..."
19
- system %{bundle}
20
- end
3
+ puts "Bundling..."
4
+ system %{bundle}
21
5
 
22
6
  puts "Installing git hooks"
23
7
  system %{script/install-git-hooks}
@@ -1,23 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- if File.file?('Gemfile.erb')
4
- pwd = Dir.pwd
5
-
6
- Dir.chdir '..' do
7
- File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
8
- repo = line[%r{:git => (['"])([^'"]+)\1}, 2]
9
-
10
- puts "Installing #{repo}"
11
- system %{git clone #{repo}}
12
- end
13
- end
14
-
15
- puts "Bundling for local environment"
16
- system %{script/gemfile local}
17
- else
18
- puts "Bundling..."
19
- system %{bundle}
20
- end
3
+ puts "Bundling..."
4
+ system %{bundle}
21
5
 
22
6
  puts "Installing git hooks"
23
7
  system %{script/install-git-hooks}
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.24
4
+ version: 0.2.26
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-10-04 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -140,7 +140,6 @@ files:
140
140
  - bin/penchant
141
141
  - config/cucumber.yml
142
142
  - features/cli.feature
143
- - features/gemfile.feature
144
143
  - features/ruby_gemfile.feature
145
144
  - features/step_definitions/given/i_am_on_the_linux_platform.rb
146
145
  - features/step_definitions/given/i_expect_git_hooks_to_be_installed.rb
@@ -163,9 +162,16 @@ files:
163
162
  - features/support/cuke-pack.rb
164
163
  - features/support/env.rb
165
164
  - lib/penchant.rb
165
+ - lib/penchant/custom_property.rb
166
+ - lib/penchant/defaults.rb
166
167
  - lib/penchant/dot_penchant.rb
168
+ - lib/penchant/env.rb
169
+ - lib/penchant/file_processor.rb
167
170
  - lib/penchant/gemfile.rb
168
171
  - lib/penchant/hooks.rb
172
+ - lib/penchant/property_stack.rb
173
+ - lib/penchant/property_stack_builder.rb
174
+ - lib/penchant/property_stack_processor.rb
169
175
  - lib/penchant/repo.rb
170
176
  - lib/penchant/version.rb
171
177
  - penchant.gemspec
@@ -175,10 +181,6 @@ files:
175
181
  - script/hooks/pre-commit
176
182
  - script/initialize-environment
177
183
  - script/install-git-hooks
178
- - spec/lib/penchant/dot_penchant_spec.rb
179
- - spec/lib/penchant/gemfile_spec.rb
180
- - spec/lib/penchant_spec.rb
181
- - spec/spec_helper.rb
182
184
  - template/script/gemfile
183
185
  - template/script/hooks/commit-msg
184
186
  - template/script/hooks/post-commit
@@ -199,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
201
  version: '0'
200
202
  segments:
201
203
  - 0
202
- hash: -3136912616894151920
204
+ hash: -2642462117175779427
203
205
  required_rubygems_version: !ruby/object:Gem::Requirement
204
206
  none: false
205
207
  requirements:
@@ -208,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
210
  version: '0'
209
211
  segments:
210
212
  - 0
211
- hash: -3136912616894151920
213
+ hash: -2642462117175779427
212
214
  requirements: []
213
215
  rubyforge_project: penchant
214
216
  rubygems_version: 1.8.23
@@ -218,7 +220,6 @@ summary: Things I do for my Rails projects to get up to speed in new environment
218
220
  fast
219
221
  test_files:
220
222
  - features/cli.feature
221
- - features/gemfile.feature
222
223
  - features/ruby_gemfile.feature
223
224
  - features/step_definitions/given/i_am_on_the_linux_platform.rb
224
225
  - features/step_definitions/given/i_expect_git_hooks_to_be_installed.rb
@@ -240,7 +241,3 @@ test_files:
240
241
  - features/step_definitions/when/i_run_in.rb
241
242
  - features/support/cuke-pack.rb
242
243
  - features/support/env.rb
243
- - spec/lib/penchant/dot_penchant_spec.rb
244
- - spec/lib/penchant/gemfile_spec.rb
245
- - spec/lib/penchant_spec.rb
246
- - spec/spec_helper.rb
@@ -1,123 +0,0 @@
1
- @fakefs
2
- Feature: Gemfiles
3
- Scenario: When rebuilding for deployment, save the original state
4
- Given I have the file "Gemfile.erb" with the content:
5
- """
6
- this is content
7
- """
8
- And I have the file "Gemfile" with the content:
9
- """
10
- # generated by penchant, environment: local
11
- """
12
- When I rebuild the Gemfile for "production" mode with deployment
13
- Then the file "Gemfile" should have the following content:
14
- """
15
- # generated by penchant, environment: production, deployment mode (was local)
16
- this is content
17
- """
18
-
19
- Scenario: When unbundling from deployment with an original state, switch to that state
20
- Given I have the file "Gemfile.erb" with the content:
21
- """
22
- this is content
23
- """
24
- And I have the file "Gemfile" with the content:
25
- """
26
- # generated by penchant, environment: production, deployment mode (was local)
27
- """
28
- When I rebuild the Gemfile asking to switch back to the previous state
29
- Then the file "Gemfile" should have the following content:
30
- """
31
- # generated by penchant, environment: local
32
- this is content
33
- """
34
-
35
- Scenario: Simple env
36
- Given I have the file "Gemfile.erb" with the content:
37
- """
38
- gem 'test'
39
- <% env :local do %>
40
- gem 'test'
41
- <% end %>
42
- """
43
- When I rebuild the Gemfile for "local" mode
44
- Then the file "Gemfile" should have the following stripped content:
45
- """
46
- # generated by penchant, environment: local
47
- gem 'test'
48
- gem 'test'
49
- """
50
-
51
- Scenario: Use placeholder expansion
52
- Given I have the file "Gemfile.erb" with the content:
53
- """
54
- <% env :local, :path => '../%s' do %>
55
- gem 'test'
56
- <% end %>
57
- """
58
- When I rebuild the Gemfile for "local" mode
59
-
60
- Then the file "Gemfile" should have the following stripped content:
61
- """
62
- # generated by penchant, environment: local
63
- gem 'test', {:path=>"../test"}
64
- """
65
-
66
- Scenario: Use a gem list for an operation
67
- Given I have the file "Gemfile.erb" with the content:
68
- """
69
- <% gems 'test' do %>
70
- <% env :local, :path => '../%s' do %>
71
- <%= gem %>
72
- <% end %>
73
- <% end %>
74
- """
75
- When I rebuild the Gemfile for "local" mode
76
- Then the file "Gemfile" should have the following stripped content:
77
- """
78
- # generated by penchant, environment: local
79
- gem 'test', {:path=>"../test"}
80
- """
81
-
82
- Scenario: Let gem get additional info
83
- Given I have the file "Gemfile.erb" with the content:
84
- """
85
- <% gems 'test' do %>
86
- <%= gem :path => '../%s' %>
87
- <% end %>
88
- """
89
- When I rebuild the Gemfile for "local" mode
90
- Then the file "Gemfile" should have the following content:
91
- """
92
- # generated by penchant, environment: local
93
-
94
- gem 'test', {:path=>"../test"}
95
-
96
- """
97
-
98
- Scenario: Use a gem list without a block
99
- Given I have the file "Gemfile.erb" with the content:
100
- """
101
- <% gems 'test', :path => '../%s' %>
102
- """
103
- When I rebuild the Gemfile for "local" mode
104
- Then the file "Gemfile" should have the following content:
105
- """
106
- # generated by penchant, environment: local
107
- gem 'test', {:path=>"../test"}
108
-
109
- """
110
-
111
- Scenario: Use a gem list with an array
112
- Given I have the file "Gemfile.erb" with the content:
113
- """
114
- <% gems [ 'test' ], :path => '../%s' %>
115
- """
116
- When I rebuild the Gemfile for "local" mode
117
- Then the file "Gemfile" should have the following content:
118
- """
119
- # generated by penchant, environment: local
120
- gem 'test', {:path=>"../test"}
121
-
122
- """
123
-
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Penchant::DotPenchant do
4
- include FakeFS::SpecHelpers
5
-
6
- describe '.run' do
7
- before do
8
- File.open('.penchant', 'wb') { |fh|
9
- fh.puts "@did_run = env"
10
- }
11
- end
12
-
13
- it 'should run the file in the environment' do
14
- dot_file = Penchant::DotPenchant.run(:this)
15
-
16
- dot_file.instance_variable_get(:@did_run).should == :this
17
- end
18
- end
19
-
20
- let(:dot_file) { described_class.new }
21
-
22
- describe '#rake' do
23
- context 'without Gemfile' do
24
- before do
25
- Kernel.expects(:system).with('rake task1 task2')
26
- end
27
-
28
- it 'should run the rake task via system' do
29
- dot_file.rake("task1", "task2")
30
- end
31
- end
32
-
33
- context 'with Gemfile' do
34
- before do
35
- File.open('Gemfile', 'wb')
36
- Kernel.expects(:system).with('bundle exec rake task1 task2')
37
- end
38
-
39
- it 'should run the rake task via system' do
40
- dot_file.rake("task1", "task2")
41
- end
42
- end
43
- end
44
- end
45
-
@@ -1,296 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Penchant::Gemfile do
4
- include FakeFS::SpecHelpers
5
-
6
- let(:dir) { File.expand_path(Dir.pwd) }
7
- let(:gemfile) { described_class.new(dir) }
8
-
9
- let(:gemfile_path) { File.join(dir, 'Gemfile') }
10
- let(:gemfile_erb_path) { File.join(dir, 'Gemfile.erb') }
11
-
12
- def write_file(path, content = nil)
13
- FileUtils.mkdir_p(File.dirname(path))
14
-
15
- File.open(path, 'wb') do |fh|
16
- content = yield if block_given?
17
- fh.print content
18
- end
19
- end
20
-
21
- subject { gemfile }
22
-
23
- context 'with no gemfile' do
24
- it { should_not have_gemfile }
25
- it { should_not have_gemfile_erb }
26
- end
27
-
28
- context 'with gemfile' do
29
- let(:data) { "whatever" }
30
-
31
- before do
32
- write_file(gemfile_path) { data }
33
- end
34
-
35
- describe 'existence' do
36
- it { should have_gemfile }
37
- it { should_not have_gemfile_erb }
38
- end
39
-
40
- describe '#environment' do
41
- context 'not defined' do
42
- its(:environment) { should be_nil }
43
- end
44
-
45
- context 'defined' do
46
- let(:environment) { 'test' }
47
- let(:data) { <<-GEMFILE }
48
- # generated by penchant, environment: #{environment}
49
- GEMFILE
50
-
51
- its(:environment) { should == environment }
52
- it { should_not be_deployment }
53
- end
54
-
55
- context 'deployment' do
56
- let(:environment) { 'test' }
57
- let(:data) { <<-GEMFILE }
58
- # generated by penchant, environment: #{environment}, deployment mode
59
- GEMFILE
60
-
61
- its(:environment) { should == environment }
62
- it { should be_deployment }
63
- end
64
- end
65
-
66
- describe '#switch_to!' do
67
- it 'should raise an exception' do
68
- expect { subject.switch_to!(:whatever) }.to raise_error(Errno::ENOENT)
69
- end
70
- end
71
- end
72
-
73
- context 'with gemfile.erb' do
74
- let(:erb_data) { 'whatever' }
75
-
76
- before do
77
- write_file(gemfile_erb_path) { erb_data }
78
- end
79
-
80
- it { should_not have_gemfile }
81
- it { should have_gemfile_erb }
82
-
83
- describe '#switch_to!' do
84
- let(:erb_data) { <<-ERB }
85
- <% env :test do %>
86
- test
87
- <% end %>
88
-
89
- <% env :not do %>
90
- not
91
- <% end %>
92
-
93
- <% no_deployment do %>
94
- diddeploy
95
- <% end %>
96
-
97
- all
98
- ERB
99
-
100
- it 'should render test data' do
101
- subject.switch_to!(:test)
102
-
103
- File.read('Gemfile').should include('test')
104
- File.read('Gemfile').should include('diddeploy')
105
- File.read('Gemfile').should_not include('not')
106
- File.read('Gemfile').should include('all')
107
- end
108
-
109
- it 'should not render test data' do
110
- subject.switch_to!(:not)
111
-
112
- File.read('Gemfile').should_not include('test')
113
- File.read('Gemfile').should include('diddeploy')
114
- File.read('Gemfile').should include('not')
115
- File.read('Gemfile').should include('all')
116
- end
117
-
118
- it 'should not render either' do
119
- subject.switch_to!
120
-
121
- File.read('Gemfile').should_not include('test')
122
- File.read('Gemfile').should_not include('not')
123
- File.read('Gemfile').should include('diddeploy')
124
- File.read('Gemfile').should include('all')
125
- end
126
-
127
- it 'should skip no_deployment sections' do
128
- subject.switch_to!(nil, true)
129
-
130
- File.read('Gemfile').should_not include('test')
131
- File.read('Gemfile').should_not include('not')
132
- File.read('Gemfile').should_not include('diddeploy')
133
- File.read('Gemfile').should include('all')
134
- end
135
-
136
- it { should_not have_dot_penchant }
137
-
138
- context 'with .penchant' do
139
- before do
140
- File.open('.penchant', 'wb')
141
- end
142
-
143
- it { should have_dot_penchant }
144
-
145
- it 'should process the file' do
146
- subject.switch_to!(:not)
147
- end
148
- end
149
- end
150
- end
151
-
152
- describe '#switch_to!' do
153
- let(:template) { 'source' }
154
- let(:gemfile_path) { 'gemfile path' }
155
- let(:header) { 'header' }
156
-
157
- let(:gemfile_out) { File.read(gemfile_path) }
158
-
159
- before do
160
- gemfile.stubs(:template).returns(template)
161
- gemfile.stubs(:gemfile_path).returns(gemfile_path)
162
-
163
- gemfile.expects(:header).returns(header)
164
- end
165
-
166
- it 'should write out the new gemfile' do
167
- gemfile.switch_to!
168
-
169
- gemfile_out.should include(template)
170
- gemfile_out.should include(header)
171
- end
172
- end
173
-
174
- describe '#header' do
175
- subject { gemfile.header }
176
-
177
- let(:env) { 'env' }
178
- let(:prior_environment) { 'prior' }
179
-
180
- before do
181
- gemfile.stubs(:current_env).returns(env)
182
- gemfile.stubs(:environment).returns(prior_environment)
183
- end
184
-
185
- context 'not deployment' do
186
- before do
187
- gemfile.stubs(:is_deployment).returns(false)
188
- end
189
-
190
- it { should == "# generated by penchant, environment: #{env}" }
191
- end
192
-
193
- context 'deployment' do
194
- before do
195
- gemfile.stubs(:is_deployment).returns(true)
196
- end
197
-
198
- it { should == "# generated by penchant, environment: #{env}, deployment mode (was #{prior_environment})" }
199
- end
200
- end
201
-
202
- describe '#prior_environment' do
203
- subject { gemfile.prior_environment }
204
-
205
- let(:prior) { 'prior' }
206
-
207
- before do
208
- gemfile.stubs(:gemfile_header).returns("# header (was #{prior})")
209
- end
210
-
211
- it { should == prior }
212
- end
213
-
214
- describe '.switch_back!' do
215
- let(:gemfile) { stub }
216
- let(:fallback_env) { 'env' }
217
-
218
- context 'pre_switch fails' do
219
- before do
220
- described_class.stubs(:pre_switch).returns(false)
221
-
222
- gemfile.expects(:switch_back!).never
223
- end
224
-
225
- it 'should not switch back' do
226
- described_class.switch_back!(fallback_env).should be_false
227
- end
228
- end
229
-
230
- context 'pre_switch succeeds' do
231
- before do
232
- described_class.stubs(:pre_switch).returns(gemfile)
233
-
234
- gemfile.expects(:switch_back!).with(fallback_env)
235
- end
236
-
237
- it 'should switch back' do
238
- described_class.switch_back!(fallback_env)
239
- end
240
- end
241
- end
242
-
243
- describe '.pre_switch' do
244
- subject { described_class.pre_switch(env, deployment) }
245
-
246
- let(:env) { 'env' }
247
- let(:deployment) { 'deployment' }
248
-
249
- context 'no Gemfile.erb' do
250
- before do
251
- described_class.any_instance.expects(:has_gemfile_erb?).returns(false)
252
- end
253
-
254
- it { should be_false }
255
- end
256
-
257
- context 'Gemfile.erb' do
258
- before do
259
- described_class.any_instance.expects(:has_gemfile_erb?).returns(true)
260
- described_class.any_instance.expects(:run_dot_penchant!).with(env, deployment)
261
- end
262
-
263
- it { should be_a_kind_of(described_class) }
264
- end
265
- end
266
-
267
- describe '#switch_back!' do
268
- let(:fallback_env) { 'fallback' }
269
- let(:prior) { 'prior' }
270
-
271
- context 'no prior' do
272
- before do
273
- gemfile.stubs(:prior_environment).returns(nil)
274
-
275
- gemfile.expects(:switch_to!).with(fallback_env)
276
- end
277
-
278
- it 'should proxy through to switch_to!' do
279
- gemfile.switch_back!(fallback_env)
280
- end
281
- end
282
-
283
- context 'prior' do
284
- before do
285
- gemfile.stubs(:prior_environment).returns(prior)
286
-
287
- gemfile.expects(:switch_to!).with(prior)
288
- end
289
-
290
- it 'should proxy through to switch_to!' do
291
- gemfile.switch_back!(fallback_env)
292
- end
293
- end
294
- end
295
- end
296
-