penchant 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -5
- data/bin/penchant +25 -7
- data/lib/penchant/dot_penchant.rb +28 -0
- data/lib/penchant/gemfile.rb +10 -2
- data/lib/penchant/version.rb +1 -1
- data/lib/penchant.rb +1 -0
- data/script/gemfile +1 -0
- data/spec/lib/penchant/dot_penchant_spec.rb +45 -0
- data/spec/lib/penchant/gemfile_spec.rb +14 -0
- data/template/script/initialize-environment +1 -1
- metadata +10 -4
data/README.md
CHANGED
@@ -19,11 +19,6 @@ Installs a bunch of scripts into the `scripts` directory of your project:
|
|
19
19
|
* `hooks/pre-commit`, one of the hooks the prior script installs
|
20
20
|
* `initialize-environment`, which bootstraps your local environment so you can get up and running
|
21
21
|
|
22
|
-
## initialize-environment
|
23
|
-
|
24
|
-
It will also try to run `rake bootstrap`, so add a `:bootstrap` task for things that should happen when you start going
|
25
|
-
(make databases, other stuff, etc, whatever). This won't run if the `:bootstrap` task is not there.
|
26
|
-
|
27
22
|
## Gemfile.erb?!
|
28
23
|
|
29
24
|
Yeah, it's a `Gemfile` with ERB in it:
|
@@ -43,6 +38,26 @@ It then runs `bundle install`.
|
|
43
38
|
|
44
39
|
You can also run `penchant gemfile ENV`.
|
45
40
|
|
41
|
+
## initialize-environment
|
42
|
+
|
43
|
+
Get new developers up to speed fast! `script/initialize-environment` does the following when run:
|
44
|
+
|
45
|
+
* Check out any remote repos found in `Gemfile.erb` to the same directory where your current project lives.
|
46
|
+
That way, you can have your `Gemfile.erb` set up as above and everything works cleanly.
|
47
|
+
* Runs `script/gemfile remote` to set your project to using remote repositories.
|
48
|
+
* Runs `rake bootstrap` for the project if it exists.
|
49
|
+
|
50
|
+
### After-`gemfile` hooks?
|
51
|
+
|
52
|
+
Drop a file called `.penchant` in your project directory. It'll get executed every time you switch environments using
|
53
|
+
Penchant. I use it to tell my Hydra clients to sync and update their Gemfiles, too:
|
54
|
+
|
55
|
+
``` ruby
|
56
|
+
# rake knows if you need "bundle exec" or not.
|
57
|
+
|
58
|
+
rake "hydra:sync hydra:remote:bundle"
|
59
|
+
```
|
60
|
+
|
46
61
|
### What environment are you currently using in that Gemfile?
|
47
62
|
|
48
63
|
`head -n 1` that puppy, or `penchant gemfile-env`.
|
data/bin/penchant
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'thor'
|
5
5
|
require 'penchant'
|
6
|
+
require 'fileutils'
|
6
7
|
|
7
8
|
class PenchantCLI < Thor
|
8
9
|
include Thor::Actions
|
@@ -19,21 +20,38 @@ class PenchantCLI < Thor
|
|
19
20
|
method_options :dir => 'script'
|
20
21
|
def convert
|
21
22
|
install
|
22
|
-
|
23
|
-
remove_file 'Gemfile'
|
23
|
+
FileUtils.mv 'Gemfile', 'Gemfile.erb'
|
24
24
|
gemfile(:remote)
|
25
25
|
end
|
26
26
|
|
27
|
-
desc "gemfile ENV", "Switch the gemfile environment"
|
28
|
-
def gemfile(env)
|
29
|
-
|
27
|
+
desc "gemfile ENV", "Switch the gemfile environment, or rebuild the current environment if not given"
|
28
|
+
def gemfile(env = get_current_env)
|
29
|
+
if env
|
30
|
+
puts "[penchant] Rebunding for #{env} environment..."
|
31
|
+
Penchant::Gemfile.do_full_env_switch!(env)
|
32
|
+
end
|
33
|
+
|
34
|
+
gemfile = Penchant::Gemfile.new
|
35
|
+
if !gemfile.has_gemfile?
|
36
|
+
puts "No Gemfile or Gemfile.erb, exiting."
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
system %{bundle}
|
30
40
|
end
|
31
41
|
|
32
42
|
desc "gemfile-env", "Get the gemfile environment"
|
33
43
|
def gemfile_env
|
34
|
-
|
35
|
-
puts gemfile.environment
|
44
|
+
puts get_current_env
|
36
45
|
end
|
46
|
+
|
47
|
+
no_tasks do
|
48
|
+
def get_current_env
|
49
|
+
gemfile = Penchant::Gemfile.new
|
50
|
+
gemfile.environment
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
default_task :gemfile
|
37
55
|
end
|
38
56
|
|
39
57
|
PenchantCLI.start
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Penchant
|
2
|
+
class DotPenchant
|
3
|
+
class << self
|
4
|
+
def run(env = nil)
|
5
|
+
dot_penchant = new
|
6
|
+
dot_penchant.run(env)
|
7
|
+
dot_penchant
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(env = nil)
|
12
|
+
instance_eval(File.read('.penchant'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def rake(*tasks)
|
16
|
+
command = [ "rake", *tasks ]
|
17
|
+
command.unshift("bundle exec") if gemfile?
|
18
|
+
Kernel.system command.join(' ')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def gemfile?
|
23
|
+
File.file?('Gemfile')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/penchant/gemfile.rb
CHANGED
@@ -7,13 +7,13 @@ module Penchant
|
|
7
7
|
class << self
|
8
8
|
def do_full_env_switch!(env)
|
9
9
|
gemfile = Penchant::Gemfile.new
|
10
|
+
gemfile.run_dot_penchant!(env)
|
11
|
+
|
10
12
|
if !gemfile.has_gemfile_erb?
|
11
|
-
puts "Not using Gemfile.erb, exiting."
|
12
13
|
return false
|
13
14
|
end
|
14
15
|
|
15
16
|
gemfile.switch_to!(env)
|
16
|
-
system %{bundle}
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -29,6 +29,10 @@ module Penchant
|
|
29
29
|
File.file?('Gemfile')
|
30
30
|
end
|
31
31
|
|
32
|
+
def has_dot_penchant?
|
33
|
+
File.file?('.penchant')
|
34
|
+
end
|
35
|
+
|
32
36
|
def gemfile_erb_path
|
33
37
|
file_in_path('Gemfile.erb')
|
34
38
|
end
|
@@ -52,6 +56,10 @@ module Penchant
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
def run_dot_penchant!(env)
|
60
|
+
DotPenchant.run(env || environment) if has_dot_penchant?
|
61
|
+
end
|
62
|
+
|
55
63
|
private
|
56
64
|
def file_in_path(file)
|
57
65
|
File.join(@path, file)
|
data/lib/penchant/version.rb
CHANGED
data/lib/penchant.rb
CHANGED
data/script/gemfile
CHANGED
@@ -0,0 +1,45 @@
|
|
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
|
+
|
@@ -103,6 +103,20 @@ ERB
|
|
103
103
|
File.read('Gemfile').should_not include('not')
|
104
104
|
File.read('Gemfile').should include('all')
|
105
105
|
end
|
106
|
+
|
107
|
+
it { should_not have_dot_penchant }
|
108
|
+
|
109
|
+
context 'with .penchant' do
|
110
|
+
before do
|
111
|
+
File.open('.penchant', 'wb')
|
112
|
+
end
|
113
|
+
|
114
|
+
it { should have_dot_penchant }
|
115
|
+
|
116
|
+
it 'should process the file' do
|
117
|
+
subject.switch_to!(:not)
|
118
|
+
end
|
119
|
+
end
|
106
120
|
end
|
107
121
|
end
|
108
122
|
end
|
@@ -5,7 +5,7 @@ if File.file?('Gemfile.erb')
|
|
5
5
|
|
6
6
|
Dir.chdir '..' do
|
7
7
|
File.readlines(File.join(pwd, 'Gemfile.erb')).find_all { |line| line[':git'] }.each do |line|
|
8
|
-
repo = line[%r{:git => (['"])(
|
8
|
+
repo = line[%r{:git => (['"])([^'"]+)\1}, 2]
|
9
9
|
|
10
10
|
puts "Installing #{repo}"
|
11
11
|
system %{git clone #{repo}}
|
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.
|
4
|
+
version: 0.0.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: 2011-
|
12
|
+
date: 2011-09-14 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
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- bin/penchant
|
29
29
|
- lib/penchant.rb
|
30
|
+
- lib/penchant/dot_penchant.rb
|
30
31
|
- lib/penchant/gemfile.rb
|
31
32
|
- lib/penchant/version.rb
|
32
33
|
- penchant.gemspec
|
@@ -34,6 +35,7 @@ files:
|
|
34
35
|
- script/hooks/pre-commit
|
35
36
|
- script/initialize-environment
|
36
37
|
- script/install-git-hooks
|
38
|
+
- spec/lib/penchant/dot_penchant_spec.rb
|
37
39
|
- spec/lib/penchant/gemfile_spec.rb
|
38
40
|
- spec/lib/penchant_spec.rb
|
39
41
|
- spec/spec_helper.rb
|
@@ -61,9 +63,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
63
|
version: '0'
|
62
64
|
requirements: []
|
63
65
|
rubyforge_project: penchant
|
64
|
-
rubygems_version: 1.8.
|
66
|
+
rubygems_version: 1.8.9
|
65
67
|
signing_key:
|
66
68
|
specification_version: 3
|
67
69
|
summary: Things I do for my Rails projects to get up to speed in new environments
|
68
70
|
fast
|
69
|
-
test_files:
|
71
|
+
test_files:
|
72
|
+
- spec/lib/penchant/dot_penchant_spec.rb
|
73
|
+
- spec/lib/penchant/gemfile_spec.rb
|
74
|
+
- spec/lib/penchant_spec.rb
|
75
|
+
- spec/spec_helper.rb
|