buckshot 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ # Buckshot
2
+
3
+ Helps to switch between shotgun and thin appropriately. Can be used inside
4
+ your Procfile to allow you to use shotgun easily for development.
5
+
6
+ $ RAILS_ENV=development PORT=4000 buckshot
7
+ # shotgun -p 4000 -E development
8
+
9
+ $ RAILS_ENV=production PORT=4000 buckshot
10
+ # thin start -p 4000 -e production
@@ -0,0 +1,60 @@
1
+ require "rake"
2
+ require "rspec"
3
+ require "rspec/core/rake_task"
4
+
5
+ $:.unshift File.expand_path("../lib", __FILE__)
6
+ require "buckshot"
7
+
8
+ task :default => :spec
9
+
10
+ desc "Run all specs"
11
+ Rspec::Core::RakeTask.new(:spec) do |t|
12
+ t.pattern = 'spec/**/*_spec.rb'
13
+ end
14
+
15
+ desc "Generate RCov code coverage report"
16
+ task :rcov => "rcov:build" do
17
+ %x{ open coverage/index.html }
18
+ end
19
+
20
+ Rspec::Core::RakeTask.new("rcov:build") do |t|
21
+ t.pattern = 'spec/**/*_spec.rb'
22
+ t.rcov = true
23
+ t.rcov_opts = [ "--exclude", Gem.default_dir , "--exclude", "spec" ]
24
+ end
25
+
26
+ ######################################################
27
+
28
+ begin
29
+ require 'jeweler'
30
+ Jeweler::Tasks.new do |s|
31
+ s.name = "buckshot"
32
+ s.version = Buckshot::VERSION
33
+
34
+ s.summary = "Helper for switching between shotgun and thin"
35
+ s.description = s.summary
36
+ s.author = "David Dollar"
37
+ s.email = "ddollar@gmail.com"
38
+ s.homepage = "http://github.com/ddollar/buckshot"
39
+
40
+ s.platform = Gem::Platform::RUBY
41
+ s.has_rdoc = false
42
+
43
+ s.files = %w(Rakefile README.md) + Dir["{bin,lib,spec}/**/*"]
44
+ s.require_path = "lib"
45
+
46
+ s.default_executable = "buckshot"
47
+
48
+ s.add_development_dependency 'fakefs', '~> 0.2.1'
49
+ s.add_development_dependency 'rake', '~> 0.8.7'
50
+ s.add_development_dependency 'rcov', '~> 0.9.8'
51
+ s.add_development_dependency 'rr', '~> 0.10.11'
52
+ s.add_development_dependency 'rspec', '~> 2.0.0'
53
+
54
+ s.add_dependency 'shotgun'
55
+ s.add_dependency 'thin'
56
+ end
57
+ Jeweler::GemcutterTasks.new
58
+ rescue LoadError
59
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
60
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path("../../lib", __FILE__)
4
+
5
+ require "buckshot"
6
+
7
+ Buckshot.start
@@ -0,0 +1,30 @@
1
+ class Buckshot
2
+
3
+ VERSION = "0.0.2"
4
+
5
+ def self.start
6
+ case environment
7
+ when "development" then start_shotgun
8
+ else start_thin
9
+ end
10
+ end
11
+
12
+ def self.start_shotgun
13
+ system "shotgun -p #{port} -E #{environment}"
14
+ end
15
+
16
+ def self.start_thin
17
+ system "thin start -p #{port} -e #{environment}"
18
+ end
19
+
20
+ private ######################################################################
21
+
22
+ def self.environment
23
+ ENV["RACK_ENV"] || "development"
24
+ end
25
+
26
+ def self.port
27
+ (ENV["PORT"] || 3000).to_i
28
+ end
29
+
30
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+ require "buckshot"
3
+
4
+ describe Buckshot do
5
+
6
+ describe "VERSION" do
7
+ subject { Buckshot::VERSION }
8
+ it { should be_a String }
9
+ end
10
+
11
+ describe "environment detection" do
12
+ it "defaults to development environment" do
13
+ Buckshot.environment.should == "development"
14
+ end
15
+
16
+ it "reads environment from RACK_ENV" do
17
+ ENV["RACK_ENV"] = "staging"
18
+ Buckshot.environment.should == "staging"
19
+ ENV.delete("RACK_ENV")
20
+ end
21
+ end
22
+
23
+ describe "port detection" do
24
+ it "defaults to 3000" do
25
+ Buckshot.port.should == 3000
26
+ end
27
+
28
+ it "reads environment from RACK_ENV" do
29
+ ENV["PORT"] = "4000"
30
+ Buckshot.port.should == 4000
31
+ ENV.delete("PORT")
32
+ end
33
+ end
34
+
35
+ describe "development mode" do
36
+ before(:each) { ENV["RACK_ENV"] = "development" }
37
+ after(:each) { ENV.delete("RACK_ENV") }
38
+
39
+ it "uses shotgun" do
40
+ Buckshot.should_receive(:start_shotgun)
41
+ Buckshot.start
42
+ end
43
+ end
44
+
45
+ describe "production mode" do
46
+ before(:each) { ENV["RACK_ENV"] = "production" }
47
+ after(:each) { ENV.delete("RACK_ENV") }
48
+
49
+ it "uses thin" do
50
+ Buckshot.should_receive(:start_thin)
51
+ Buckshot.start
52
+ end
53
+ end
54
+
55
+ describe "start_shotgun" do
56
+ it "executes shotgun correctly" do
57
+ Buckshot.should_receive(:environment).and_return("development")
58
+ Buckshot.should_receive(:port).and_return("5000")
59
+ Buckshot.should_receive(:system).with("shotgun -p 5000 -E development")
60
+ Buckshot.start_shotgun
61
+ end
62
+ end
63
+
64
+ describe "start_thin" do
65
+ it "executes thin correctly" do
66
+ Buckshot.should_receive(:environment).and_return("production")
67
+ Buckshot.should_receive(:port).and_return("5000")
68
+ Buckshot.should_receive(:system).with("thin start -p 5000 -e production")
69
+ Buckshot.start_thin
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,8 @@
1
+ require "rubygems"
2
+ require "rspec"
3
+
4
+ $:.unshift "lib"
5
+
6
+ Rspec.configure do |config|
7
+ config.color_enabled = true
8
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buckshot
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - David Dollar
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-30 00:00:00 -04:00
19
+ default_executable: buckshot
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: fakefs
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 21
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 1
34
+ version: 0.2.1
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 49
46
+ segments:
47
+ - 0
48
+ - 8
49
+ - 7
50
+ version: 0.8.7
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rcov
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 43
62
+ segments:
63
+ - 0
64
+ - 9
65
+ - 8
66
+ version: 0.9.8
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: rr
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 33
78
+ segments:
79
+ - 0
80
+ - 10
81
+ - 11
82
+ version: 0.10.11
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 15
94
+ segments:
95
+ - 2
96
+ - 0
97
+ - 0
98
+ version: 2.0.0
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: shotgun
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ type: :runtime
114
+ version_requirements: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ name: thin
117
+ prerelease: false
118
+ requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ type: :runtime
128
+ version_requirements: *id007
129
+ description: Helper for switching between shotgun and thin
130
+ email: ddollar@gmail.com
131
+ executables:
132
+ - buckshot
133
+ extensions: []
134
+
135
+ extra_rdoc_files:
136
+ - README.md
137
+ files:
138
+ - README.md
139
+ - Rakefile
140
+ - bin/buckshot
141
+ - lib/buckshot.rb
142
+ - spec/buckshot_spec.rb
143
+ - spec/spec_helper.rb
144
+ has_rdoc: false
145
+ homepage: http://github.com/ddollar/buckshot
146
+ licenses: []
147
+
148
+ post_install_message:
149
+ rdoc_options:
150
+ - --charset=UTF-8
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ hash: 3
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ hash: 3
168
+ segments:
169
+ - 0
170
+ version: "0"
171
+ requirements: []
172
+
173
+ rubyforge_project:
174
+ rubygems_version: 1.3.7
175
+ signing_key:
176
+ specification_version: 3
177
+ summary: Helper for switching between shotgun and thin
178
+ test_files:
179
+ - spec/buckshot_spec.rb
180
+ - spec/spec_helper.rb