penchant 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +10 -0
- data/Guardfile +9 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/bin/penchant +39 -0
- data/lib/penchant/gemfile.rb +65 -0
- data/lib/penchant/version.rb +3 -0
- data/lib/penchant.rb +3 -0
- data/penchant.gemspec +21 -0
- data/spec/lib/penchant/gemfile_spec.rb +109 -0
- data/spec/lib/penchant_spec.rb +0 -0
- data/spec/spec_helper.rb +6 -0
- data/template/script/gemfile +11 -0
- data/template/script/hooks/pre-commit +15 -0
- data/template/script/initialize-environment +35 -0
- data/template/script/install-git-hooks +6 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :cli => '-c', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# I have a penchant for setting up all my projects so they work the same.
|
2
|
+
|
3
|
+
I like to do these things in all my projects:
|
4
|
+
|
5
|
+
* Have all my tests run before committing. I don't like buying ice cream for the team on test failures.
|
6
|
+
* If I'm developing gems alongside this project, I use a `Gemfile.erb` to get around the "one gem, one source" issue in
|
7
|
+
current versions of Bundler.
|
8
|
+
* If I'm moving to different machines or (heaven forbid!) having other developers work on the project, I want to make
|
9
|
+
getting all those local gems as easy as possible.
|
10
|
+
|
11
|
+
This gem makes that easier!
|
12
|
+
|
13
|
+
## What's it do?
|
14
|
+
|
15
|
+
Installs a bunch of scripts into the `scripts` directory of your project:
|
16
|
+
|
17
|
+
* `gemfile` which switches between `Gemfile.erb` environments
|
18
|
+
* `install-git-hooks` which will do just what it says
|
19
|
+
* `hooks/pre-commit`, one of the hooks the prior script installs
|
20
|
+
* `initialize-environment`, which bootstraps your local environment so you can get up and running
|
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
|
+
## Gemfile.erb?!
|
28
|
+
|
29
|
+
Yeah, it's a `Gemfile` with ERB in it:
|
30
|
+
|
31
|
+
``` erb
|
32
|
+
<% env :local do %>
|
33
|
+
gem 'guard', :path => '../guard'
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<% env :remote do %>
|
37
|
+
gem 'guard', :git => 'git://github.com/johnbintz/guard.git'
|
38
|
+
<% end %>
|
39
|
+
```
|
40
|
+
|
41
|
+
Use `script/gemfile local` to get at the local ones, and `script/gemfile remote` to get at the remote ones.
|
42
|
+
It then runs `bundle install`.
|
43
|
+
|
44
|
+
You can also run `penchant gemfile ENV`.
|
45
|
+
|
46
|
+
### What environment are you currently using in that Gemfile?
|
47
|
+
|
48
|
+
`head -n 1` that puppy, or `penchant gemfile-env`.
|
49
|
+
|
50
|
+
## git hook?!
|
51
|
+
|
52
|
+
It runs `penchant gemfile remote` then runs `bundle exec rake`. Make sure your default Rake task for the project runs your
|
53
|
+
tests and performs any other magic necessary before each commit. Your re-environmented Gemfile and Gemfile.lock will be added
|
54
|
+
to your commit if they've changed.
|
55
|
+
|
56
|
+
## How?!
|
57
|
+
|
58
|
+
* `gem install penchant`
|
59
|
+
* `cd` to your project directory
|
60
|
+
|
61
|
+
And then one of the following:
|
62
|
+
|
63
|
+
* `penchant install` for a new project (`--dir=WHEREVER` will install the scripts to a directory other than `$PWD/scripts`)
|
64
|
+
* `penchant convert` for an existing project (`--dir=WHEVEVER` works here, too)
|
65
|
+
|
data/Rakefile
ADDED
data/bin/penchant
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'thor'
|
5
|
+
require 'penchant'
|
6
|
+
|
7
|
+
class PenchantCLI < Thor
|
8
|
+
include Thor::Actions
|
9
|
+
source_root File.expand_path('../..', __FILE__)
|
10
|
+
|
11
|
+
desc "install", "Copy the common scripts to the project"
|
12
|
+
method_options :dir => 'script'
|
13
|
+
def install
|
14
|
+
directory 'template/script', options[:dir]
|
15
|
+
Dir[File.join(options[:dir], '**/*')].each { |file| File.chmod(0755, file) }
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "convert", "Make an existing project Penchant-isized"
|
19
|
+
method_options :dir => 'script'
|
20
|
+
def convert
|
21
|
+
install
|
22
|
+
copy_file 'Gemfile', 'Gemfile.erb'
|
23
|
+
remove_file 'Gemfile'
|
24
|
+
gemfile(:remote)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "gemfile ENV", "Switch the gemfile environment"
|
28
|
+
def gemfile(env)
|
29
|
+
Penchant::Gemfile.do_full_env_switch!(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "gemfile-env", "Get the gemfile environment"
|
33
|
+
def gemfile_env
|
34
|
+
gemfile = Penchant::Gemfile.new
|
35
|
+
puts gemfile.environment
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
PenchantCLI.start
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Penchant
|
4
|
+
class Gemfile
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def do_full_env_switch!(env)
|
9
|
+
gemfile = Penchant::Gemfile.new
|
10
|
+
if !gemfile.has_gemfile_erb?
|
11
|
+
puts "Not using Gemfile.erb, exiting."
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
|
15
|
+
gemfile.switch_to!(env)
|
16
|
+
system %{bundle}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(path = Dir.pwd)
|
21
|
+
@path = path
|
22
|
+
end
|
23
|
+
|
24
|
+
def gemfile_path
|
25
|
+
file_in_path('Gemfile')
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_gemfile?
|
29
|
+
File.file?('Gemfile')
|
30
|
+
end
|
31
|
+
|
32
|
+
def gemfile_erb_path
|
33
|
+
file_in_path('Gemfile.erb')
|
34
|
+
end
|
35
|
+
|
36
|
+
def has_gemfile_erb?
|
37
|
+
File.file?(gemfile_erb_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def environment
|
41
|
+
File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1]
|
42
|
+
end
|
43
|
+
|
44
|
+
def switch_to!(gemfile_env = nil)
|
45
|
+
@env = gemfile_env
|
46
|
+
template = File.read(gemfile_erb_path)
|
47
|
+
|
48
|
+
File.open(gemfile_path, 'wb') do |fh|
|
49
|
+
fh.puts "# generated by penchant, environment: #{@env}"
|
50
|
+
|
51
|
+
fh.print ERB.new(template).result(binding)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def file_in_path(file)
|
57
|
+
File.join(@path, file)
|
58
|
+
end
|
59
|
+
|
60
|
+
def env(check, &block)
|
61
|
+
instance_eval(&block) if check.to_s == @env.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/penchant.rb
ADDED
data/penchant.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "penchant/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "penchant"
|
7
|
+
s.version = Penchant::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["John Bintz"]
|
10
|
+
s.email = ["john@coswellproductions.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Things I do for my Rails projects to get up to speed in new environments fast}
|
13
|
+
s.description = %q{Things I do for my Rails projects to get up to speed in new environments fast}
|
14
|
+
|
15
|
+
s.rubyforge_project = "penchant"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
@@ -0,0 +1,109 @@
|
|
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
|
+
File.open(path, 'wb') do |fh|
|
14
|
+
content = yield if block_given?
|
15
|
+
fh.print content
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { gemfile }
|
20
|
+
|
21
|
+
context 'with no gemfile' do
|
22
|
+
it { should_not have_gemfile }
|
23
|
+
it { should_not have_gemfile_erb }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with gemfile' do
|
27
|
+
let(:data) { "whatever" }
|
28
|
+
|
29
|
+
before do
|
30
|
+
write_file(gemfile_path) { data }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'existence' do
|
34
|
+
it { should have_gemfile }
|
35
|
+
it { should_not have_gemfile_erb }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#environment' do
|
39
|
+
context 'not defined' do
|
40
|
+
its(:environment) { should be_nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'defined' do
|
44
|
+
let(:environment) { 'test' }
|
45
|
+
let(:data) { <<-GEMFILE }
|
46
|
+
# generated by penchant, environment: #{environment}
|
47
|
+
GEMFILE
|
48
|
+
|
49
|
+
its(:environment) { should == environment }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#switch_to!' do
|
54
|
+
it 'should raise an exception' do
|
55
|
+
expect { subject.switch_to!(:whatever) }.to raise_error(Errno::ENOENT)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with gemfile.erb' do
|
61
|
+
let(:erb_data) { 'whatever' }
|
62
|
+
|
63
|
+
before do
|
64
|
+
write_file(gemfile_erb_path) { erb_data }
|
65
|
+
end
|
66
|
+
|
67
|
+
it { should_not have_gemfile }
|
68
|
+
it { should have_gemfile_erb }
|
69
|
+
|
70
|
+
describe '#switch_to!' do
|
71
|
+
let(:erb_data) { <<-ERB }
|
72
|
+
<% env :test do %>
|
73
|
+
test
|
74
|
+
<% end %>
|
75
|
+
|
76
|
+
<% env :not do %>
|
77
|
+
not
|
78
|
+
<% end %>
|
79
|
+
|
80
|
+
all
|
81
|
+
ERB
|
82
|
+
|
83
|
+
it 'should render test data' do
|
84
|
+
subject.switch_to!(:test)
|
85
|
+
|
86
|
+
File.read('Gemfile').should include('test')
|
87
|
+
File.read('Gemfile').should_not include('not')
|
88
|
+
File.read('Gemfile').should include('all')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should not render test data' do
|
92
|
+
subject.switch_to!(:not)
|
93
|
+
|
94
|
+
File.read('Gemfile').should_not include('test')
|
95
|
+
File.read('Gemfile').should include('not')
|
96
|
+
File.read('Gemfile').should include('all')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should not render either' do
|
100
|
+
subject.switch_to!
|
101
|
+
|
102
|
+
File.read('Gemfile').should_not include('test')
|
103
|
+
File.read('Gemfile').should_not include('not')
|
104
|
+
File.read('Gemfile').should include('all')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
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
|
21
|
+
|
22
|
+
puts "Installing git hooks"
|
23
|
+
system %{script/install-git-hooks}
|
24
|
+
|
25
|
+
bundle = File.file?('Gemfile') ? 'bundle exec' : ''
|
26
|
+
|
27
|
+
command = [ bundle, 'rake', '-s', '-T', 'bootstrap' ]
|
28
|
+
|
29
|
+
if !(%x{#{command.join(' ')}}).empty?
|
30
|
+
puts "Trying to run rake bootstrap..."
|
31
|
+
system %{#{bundle} rake bootstrap}
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "Done!"
|
35
|
+
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: penchant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Bintz
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-18 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Things I do for my Rails projects to get up to speed in new environments
|
15
|
+
fast
|
16
|
+
email:
|
17
|
+
- john@coswellproductions.com
|
18
|
+
executables:
|
19
|
+
- penchant
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/penchant
|
29
|
+
- lib/penchant.rb
|
30
|
+
- lib/penchant/gemfile.rb
|
31
|
+
- lib/penchant/version.rb
|
32
|
+
- penchant.gemspec
|
33
|
+
- spec/lib/penchant/gemfile_spec.rb
|
34
|
+
- spec/lib/penchant_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
- template/script/gemfile
|
37
|
+
- template/script/hooks/pre-commit
|
38
|
+
- template/script/initialize-environment
|
39
|
+
- template/script/install-git-hooks
|
40
|
+
homepage: ''
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: penchant
|
60
|
+
rubygems_version: 1.8.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Things I do for my Rails projects to get up to speed in new environments
|
64
|
+
fast
|
65
|
+
test_files: []
|