penchant 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -31,6 +31,10 @@ Yeah, it's a `Gemfile` with ERB in it:
31
31
  <% env :remote do %>
32
32
  gem 'guard', :git => 'git://github.com/johnbintz/guard.git'
33
33
  <% end %>
34
+
35
+ <% no_deployment do %>
36
+ gem 'os-specific-things'
37
+ <% end %>
34
38
  ```
35
39
 
36
40
  Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` to get at the remote ones.
@@ -38,6 +42,29 @@ It then runs `bundle install`.
38
42
 
39
43
  You can also run `penchant gemfile ENV`.
40
44
 
45
+ ### Deployment mode
46
+
47
+ Use `no_deployment` blocks to indicate gems that shouldn't even appear in `Gemfiles` destined for
48
+ remote servers. *Very* helpful when you have OS-specific gems and are developing on one platform
49
+ and deploying on another:
50
+
51
+ ``` erb
52
+ <% no_deployment do %>
53
+ require 'rbconfig'
54
+ case RbConfig::CONFIG['host_os']
55
+ when /darwin/
56
+ gem 'growl_notify'
57
+ gem 'growl'
58
+ gem 'rb-fsevent'
59
+ when /linux/
60
+ gem 'libnotify', :require => nil
61
+ end
62
+ <% end %>
63
+ ```
64
+
65
+ Run `penchant gemfile ENV --deployment` to get this behavior. This is run by default when the
66
+ pre-commit git hook runs.
67
+
41
68
  ## initialize-environment
42
69
 
43
70
  Get new developers up to speed fast! `script/initialize-environment` does the following when run:
data/bin/penchant CHANGED
@@ -14,6 +14,10 @@ class PenchantCLI < Thor
14
14
  def install
15
15
  directory 'template/script', options[:dir]
16
16
  Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) }
17
+
18
+ Dir['script/hooks/*'].each do |hook|
19
+ FileUtils.ln_sf File.join(Dir.pwd, hook), ".git/hooks/#{File.split(hook).last}"
20
+ end
17
21
  end
18
22
 
19
23
  desc "convert", "Make an existing project Penchant-isized"
@@ -24,11 +28,12 @@ class PenchantCLI < Thor
24
28
  gemfile(:remote)
25
29
  end
26
30
 
31
+ method_options :deployment => false
27
32
  desc "gemfile ENV", "Switch the gemfile environment, or rebuild the current environment if not given"
28
33
  def gemfile(env = get_current_env)
29
34
  if env
30
- puts "[penchant] Rebunding for #{env} environment..."
31
- Penchant::Gemfile.do_full_env_switch!(env)
35
+ puts "[penchant] Rebunding for #{env} environment#{options[:deployment] ? ", deployment mode" : ''}..."
36
+ Penchant::Gemfile.do_full_env_switch!(env, options[:deployment])
32
37
  end
33
38
 
34
39
  gemfile = Penchant::Gemfile.new
@@ -47,7 +52,9 @@ class PenchantCLI < Thor
47
52
  no_tasks do
48
53
  def get_current_env
49
54
  gemfile = Penchant::Gemfile.new
50
- gemfile.environment
55
+ out = [ gemfile.environment ]
56
+ out << "deployment" if gemfile.deployment?
57
+ out.join(' ')
51
58
  end
52
59
  end
53
60
 
@@ -1,14 +1,14 @@
1
1
  module Penchant
2
2
  class DotPenchant
3
3
  class << self
4
- def run(env = nil)
4
+ def run(env = nil, deployment = false)
5
5
  dot_penchant = new
6
6
  dot_penchant.run(env)
7
7
  dot_penchant
8
8
  end
9
9
  end
10
10
 
11
- def run(env = nil)
11
+ def run(env = nil, deployment = false)
12
12
  instance_eval(File.read('.penchant'))
13
13
  end
14
14
 
@@ -22,7 +22,6 @@ module Penchant
22
22
  def gemfile?
23
23
  File.file?('Gemfile')
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
 
@@ -5,15 +5,15 @@ module Penchant
5
5
  attr_reader :path
6
6
 
7
7
  class << self
8
- def do_full_env_switch!(env)
8
+ def do_full_env_switch!(env, deployment = false)
9
9
  gemfile = Penchant::Gemfile.new
10
- gemfile.run_dot_penchant!(env)
10
+ gemfile.run_dot_penchant!(env, deployment)
11
11
 
12
12
  if !gemfile.has_gemfile_erb?
13
13
  return false
14
14
  end
15
15
 
16
- gemfile.switch_to!(env)
16
+ gemfile.switch_to!(env, deployment)
17
17
  end
18
18
  end
19
19
 
@@ -42,22 +42,26 @@ module Penchant
42
42
  end
43
43
 
44
44
  def environment
45
- File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1]
45
+ File.readlines(gemfile_path).first.strip[%r{environment: ([^, ]*)}, 1]
46
46
  end
47
47
 
48
- def switch_to!(gemfile_env = nil)
49
- @env = gemfile_env
48
+ def deployment?
49
+ File.readlines(gemfile_path).first['deployment mode'] != nil
50
+ end
51
+
52
+ def switch_to!(gemfile_env = nil, deployment = false)
53
+ @env, @is_deployment = gemfile_env, deployment
50
54
  template = File.read(gemfile_erb_path)
51
55
 
52
56
  File.open(gemfile_path, 'wb') do |fh|
53
- fh.puts "# generated by penchant, environment: #{@env}"
57
+ fh.puts "# generated by penchant, environment: #{@env || "none"}#{@is_deployment ? " , deployment mode" : ""}"
54
58
 
55
59
  fh.print ERB.new(template).result(binding)
56
60
  end
57
61
  end
58
62
 
59
- def run_dot_penchant!(env)
60
- DotPenchant.run(env || environment) if has_dot_penchant?
63
+ def run_dot_penchant!(env, deployment)
64
+ DotPenchant.run(env || environment, deployment) if has_dot_penchant?
61
65
  end
62
66
 
63
67
  private
@@ -68,6 +72,10 @@ module Penchant
68
72
  def env(check, &block)
69
73
  instance_eval(&block) if check.to_s == @env.to_s
70
74
  end
75
+
76
+ def no_deployment(&block)
77
+ instance_eval(&block) if !@is_deployment
78
+ end
71
79
  end
72
80
  end
73
81
 
@@ -1,3 +1,3 @@
1
1
  module Penchant
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,7 @@ OLD_GIT_DIR=$GIT_DIR
4
4
 
5
5
  if [ "$(penchant gemfile-env)" != "remote" ]; then
6
6
  unset GIT_DIR
7
- penchant gemfile remote
7
+ penchant gemfile remote --deployment
8
8
  GIT_DIR=$OLD_GIT_DIR
9
9
  git add Gemfile*
10
10
  fi
@@ -47,6 +47,17 @@ describe Penchant::Gemfile do
47
47
  GEMFILE
48
48
 
49
49
  its(:environment) { should == environment }
50
+ it { should_not be_deployment }
51
+ end
52
+
53
+ context 'deployment' do
54
+ let(:environment) { 'test' }
55
+ let(:data) { <<-GEMFILE }
56
+ # generated by penchant, environment: #{environment}, deployment mode
57
+ GEMFILE
58
+
59
+ its(:environment) { should == environment }
60
+ it { should be_deployment }
50
61
  end
51
62
  end
52
63
 
@@ -77,6 +88,10 @@ GEMFILE
77
88
  not
78
89
  <% end %>
79
90
 
91
+ <% no_deployment do %>
92
+ diddeploy
93
+ <% end %>
94
+
80
95
  all
81
96
  ERB
82
97
 
@@ -84,6 +99,7 @@ ERB
84
99
  subject.switch_to!(:test)
85
100
 
86
101
  File.read('Gemfile').should include('test')
102
+ File.read('Gemfile').should include('diddeploy')
87
103
  File.read('Gemfile').should_not include('not')
88
104
  File.read('Gemfile').should include('all')
89
105
  end
@@ -92,6 +108,7 @@ ERB
92
108
  subject.switch_to!(:not)
93
109
 
94
110
  File.read('Gemfile').should_not include('test')
111
+ File.read('Gemfile').should include('diddeploy')
95
112
  File.read('Gemfile').should include('not')
96
113
  File.read('Gemfile').should include('all')
97
114
  end
@@ -101,6 +118,16 @@ ERB
101
118
 
102
119
  File.read('Gemfile').should_not include('test')
103
120
  File.read('Gemfile').should_not include('not')
121
+ File.read('Gemfile').should include('diddeploy')
122
+ File.read('Gemfile').should include('all')
123
+ end
124
+
125
+ it 'should skip no_deployment sections' do
126
+ subject.switch_to!(nil, true)
127
+
128
+ File.read('Gemfile').should_not include('test')
129
+ File.read('Gemfile').should_not include('not')
130
+ File.read('Gemfile').should_not include('diddeploy')
104
131
  File.read('Gemfile').should include('all')
105
132
  end
106
133
 
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ penchant gemfile remote
4
+
@@ -2,9 +2,9 @@
2
2
 
3
3
  OLD_GIT_DIR=$GIT_DIR
4
4
 
5
- if [ "$(penchant gemfile-env)" != "remote" ]; then
5
+ if [ "$(penchant gemfile-env)" != "remote deployment" ]; then
6
6
  unset GIT_DIR
7
- penchant gemfile remote
7
+ penchant gemfile remote --deployment
8
8
  GIT_DIR=$OLD_GIT_DIR
9
9
  git add Gemfile*
10
10
  fi
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.0.3
4
+ version: 0.0.5
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: 2011-09-14 00:00:00.000000000Z
12
+ date: 2011-10-13 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Things I do for my Rails projects to get up to speed in new environments
15
15
  fast
@@ -40,6 +40,7 @@ files:
40
40
  - spec/lib/penchant_spec.rb
41
41
  - spec/spec_helper.rb
42
42
  - template/script/gemfile
43
+ - template/script/hooks/post-commit
43
44
  - template/script/hooks/pre-commit
44
45
  - template/script/initialize-environment
45
46
  - template/script/install-git-hooks
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
64
  version: '0'
64
65
  requirements: []
65
66
  rubyforge_project: penchant
66
- rubygems_version: 1.8.9
67
+ rubygems_version: 1.8.11
67
68
  signing_key:
68
69
  specification_version: 3
69
70
  summary: Things I do for my Rails projects to get up to speed in new environments