Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'rails' of github.com:winton/gem_template

Conflicts:
	Rakefile
	bin/gem_template
	cap_reserve.gemspec
	config/gemsets.yml
	config/gemspec.yml
	lib/cap_reserve/gems.rb
	lib/gem_template.rb
	rails/init.rb
	spec/cap_reserve/gems_spec.rb
	spec/spec_helper.rb
  • Loading branch information...
commit 67c8bc399c47fb6f2fc7df1f0bc8dcc8d7396b64 2 parents 161eab5 + 8e9b60b
Winton Welsh authored
3  .gitignore
... ... @@ -1,5 +1,6 @@
1 1 .DS_Store
2 2 *.gem
3   -coverage
  3 +.bundle
  4 +Gemfile.lock
4 5 pkg
5 6 tmp
3  Gemfile
... ... @@ -0,0 +1,3 @@
  1 +source "http://rubygems.org"
  2 +
  3 +gemspec
95 Rakefile
... ... @@ -1,94 +1 @@
1   -require File.dirname(__FILE__) + '/lib/cap_reserve/gems'
2   -
3   -CapReserve::Gems.activate %w(rake rspec)
4   -
5   -require 'rake'
6   -
7   -begin
8   - require 'spec/rake/spectask'
9   -rescue Exception => e
10   -end
11   -
12   -def gemspec
13   - @gemspec ||= begin
14   - file = File.expand_path('../cap_reserve.gemspec', __FILE__)
15   - eval(File.read(file), binding, file)
16   - end
17   -end
18   -
19   -if defined?(Spec::Rake::SpecTask)
20   - desc "Run specs"
21   - Spec::Rake::SpecTask.new do |t|
22   - t.spec_files = FileList['spec/**/*_spec.rb']
23   - t.spec_opts = %w(-fs --color)
24   - t.warning = true
25   - end
26   - task :spec
27   - task :default => :spec
28   -end
29   -
30   -desc "Build gem(s)"
31   -task :gem do
32   - old_gemset = ENV['GEMSET']
33   - root = File.expand_path('../', __FILE__)
34   - pkg = "#{root}/pkg"
35   - system "rm -Rf #{pkg}"
36   - CapReserve::Gems.gemset_names.each do |gemset|
37   - ENV['GEMSET'] = gemset.to_s
38   - system "cd #{root} && gem build cap_reserve.gemspec"
39   - system "mkdir -p #{pkg} && mv *.gem pkg"
40   - end
41   - ENV['GEMSET'] = old_gemset
42   -end
43   -
44   -namespace :gem do
45   - desc "Install gem(s)"
46   - task :install do
47   - Rake::Task['gem'].invoke
48   - Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
49   - system "gem install #{pkg} --no-ri --no-rdoc"
50   - end
51   - end
52   -
53   - desc "Push gem(s)"
54   - task :push do
55   - Rake::Task['gem'].invoke
56   - Dir["#{File.dirname(__FILE__)}/pkg/*.gem"].each do |pkg|
57   - system "gem push #{pkg}"
58   - end
59   - end
60   -end
61   -
62   -namespace :gems do
63   - desc "Install gem dependencies (DEV=0 DOCS=0 GEMSPEC=default SUDO=0)"
64   - task :install do
65   - dev = ENV['DEV'] == '1'
66   - docs = ENV['DOCS'] == '1' ? '' : '--no-ri --no-rdoc'
67   - gemset = ENV['GEMSET']
68   - sudo = ENV['SUDO'] == '1' ? 'sudo' : ''
69   -
70   - CapReserve::Gems.gemset = gemset if gemset
71   -
72   - if dev
73   - gems = CapReserve::Gems.gemspec.development_dependencies
74   - else
75   - gems = CapReserve::Gems.gemspec.dependencies
76   - end
77   -
78   - gems.each do |name|
79   - name = name.to_s
80   - version = CapReserve::Gems.versions[name.to_sym]
81   - if Gem.source_index.find_name(name, version).empty?
82   - version = version ? "-v #{version}" : ''
83   - system "#{sudo} gem install #{name} #{version} #{docs}"
84   - else
85   - puts "already installed: #{name} #{version}"
86   - end
87   - end
88   - end
89   -end
90   -
91   -desc "Validate the gemspec"
92   -task :gemspec do
93   - gemspec.validate
94   -end
  1 +require 'bundler/gem_tasks'
33 cap_reserve.gemspec
... ... @@ -1,32 +1,25 @@
1 1 # -*- encoding: utf-8 -*-
2 2 root = File.expand_path('../', __FILE__)
3 3 lib = "#{root}/lib"
  4 +
4 5 $:.unshift lib unless $:.include?(lib)
5   -
6   -require 'cap_reserve/gems'
7   -CapReserve::Gems.gemset ||= ENV['GEMSET'] || :default
8 6
9 7 Gem::Specification.new do |s|
10   - CapReserve::Gems.gemspec.hash.each do |key, value|
11   - if key == 'name' && CapReserve::Gems.gemset != :default
12   - s.name = "#{value}-#{CapReserve::Gems.gemset}"
13   - elsif key == 'summary' && CapReserve::Gems.gemset == :solo
14   - s.summary = value + " (no dependencies)"
15   - elsif !%w(dependencies development_dependencies).include?(key)
16   - s.send "#{key}=", value
17   - end
18   - end
19   -
20   - CapReserve::Gems.dependencies.each do |g|
21   - s.add_dependency g.to_s, CapReserve::Gems.versions[g]
22   - end
23   -
24   - CapReserve::Gems.development_dependencies.each do |g|
25   - s.add_development_dependency g.to_s, CapReserve::Gems.versions[g]
26   - end
  8 + s.name = "cap_reserve"
  9 + s.version = '0.1.0'
  10 + s.platform = Gem::Platform::RUBY
  11 + s.authors = [ "Winton Welsh" ]
  12 + s.email = [ "mail@wintoni.us" ]
  13 + s.homepage = "http://guthub.com/winton/cap_reserve"
  14 + s.summary = %q{Uses a maitre_d server to reserve time on deploy environments}
  15 + s.description = %q{Uses a maitre_d server to reserve time on deploy environments.}
27 16
28 17 s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
29 18 s.files = `cd #{root} && git ls-files`.split("\n")
30 19 s.require_paths = %w(lib)
31 20 s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
  21 +
  22 + s.add_development_dependency "rspec", "~> 1.0"
  23 +
  24 + s.add_dependency "nestful", "= 0.0.7"
32 25 end
5 config/gemsets.yml
... ... @@ -1,5 +0,0 @@
1   -cap_reserve:
2   - rake: >=0.8.7
3   - rspec: ~>1.0
4   - default:
5   - nestful: =0.0.7
13 config/gemspec.yml
... ... @@ -1,13 +0,0 @@
1   -name: cap_reserve
2   -version: 0.1.0
3   -authors:
4   - - Winton Welsh
5   -email: mail@wintoni.us
6   -homepage: https://github.com/winton/cap_reserve
7   -summary:
8   -description:
9   -dependencies:
10   - - nestful
11   -development_dependencies:
12   - - rake
13   - - rspec
6 lib/cap_reserve.rb
... ... @@ -1,7 +1,5 @@
1   -require File.dirname(__FILE__) + '/cap_reserve/gems'
2   -
3   -CapReserve::Gems.activate %w(nestful)
4   -require 'nestful'
  1 +gem "nestful", "= 0.0.7"
  2 +require "nestful"
5 3
6 4 $:.unshift File.dirname(__FILE__)
7 5
159 lib/cap_reserve/gems.rb
... ... @@ -1,159 +0,0 @@
1   -unless defined?(CapReserve::Gems)
2   -
3   - require 'yaml'
4   -
5   - module CapReserve
6   - module Gems
7   - class <<self
8   -
9   - attr_accessor :config
10   - attr_reader :gemset, :gemsets, :versions
11   -
12   - class SimpleStruct
13   - attr_reader :hash
14   -
15   - def initialize(hash)
16   - @hash = hash
17   - @hash.each do |key, value|
18   - self.class.send(:define_method, key) { @hash[key] }
19   - self.class.send(:define_method, "#{key}=") { |v| @hash[key] = v }
20   - end
21   - end
22   - end
23   -
24   - Gems.config = SimpleStruct.new(
25   - :gemsets => [ "#{File.expand_path('../../../', __FILE__)}/config/gemsets.yml" ],
26   - :gemspec => "#{File.expand_path('../../../', __FILE__)}/config/gemspec.yml",
27   - :warn => true
28   - )
29   -
30   - def activate(*gems)
31   - begin
32   - require 'rubygems' unless defined?(::Gem)
33   - rescue LoadError
34   - puts "rubygems library could not be required" if @config.warn
35   - end
36   -
37   - self.gemset ||= gemset_from_loaded_specs
38   -
39   - gems.flatten.collect { |g| g.to_sym }.each do |name|
40   - version = @versions[name]
41   - vendor = File.expand_path("../../../vendor/#{name}/lib", __FILE__)
42   - warning = "#{name} #{"(#{version})" if version} failed to activate"
43   - if File.exists?(vendor)
44   - $:.unshift vendor
45   - elsif defined?(gem)
46   - begin
47   - gem name.to_s, version
48   - rescue Exception => e
49   - puts warning if @config.warn
50   - end
51   - else
52   - puts warning if @config.warn
53   - end
54   - end
55   - end
56   -
57   - def dependencies
58   - dependency_filter(@gemspec.dependencies, @gemset)
59   - end
60   -
61   - def development_dependencies
62   - dependency_filter(@gemspec.development_dependencies, @gemset)
63   - end
64   -
65   - def gemset=(gemset)
66   - if gemset
67   - @gemset = gemset.to_sym
68   -
69   - @gemsets = @config.gemsets.reverse.collect { |config|
70   - if config.is_a?(::String)
71   - YAML::load(File.read(config)) rescue {}
72   - elsif config.is_a?(::Hash)
73   - config
74   - end
75   - }.inject({}) do |hash, config|
76   - deep_merge(hash, symbolize_keys(config))
77   - end
78   -
79   - @versions = (@gemsets[gemspec.name.to_sym] || {}).inject({}) do |hash, (key, value)|
80   - if !value.is_a?(::Hash) && value
81   - hash[key] = value
82   - elsif key == @gemset
83   - (value || {}).each { |k, v| hash[k] = v }
84   - end
85   - hash
86   - end
87   - else
88   - @gemset = nil
89   - @gemsets = nil
90   - @versions = nil
91   - end
92   - end
93   -
94   - def gemset_names
95   - (
96   - [ :default ] +
97   - @gemsets[gemspec.name.to_sym].inject([]) { |array, (key, value)|
98   - array.push(key) if value.is_a?(::Hash) || value.nil?
99   - array
100   - }
101   - ).uniq
102   - end
103   -
104   - def gemspec(reload=false)
105   - if @gemspec && !reload
106   - @gemspec
107   - else
108   - data = YAML::load(File.read(@config.gemspec)) rescue {}
109   - @gemspec = SimpleStruct.new(data)
110   - end
111   - end
112   -
113   - private
114   -
115   - def deep_merge(first, second)
116   - merger = lambda do |key, v1, v2|
117   - Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2
118   - end
119   - first.merge(second, &merger)
120   - end
121   -
122   - def dependency_filter(dependencies, match)
123   - (dependencies || []).inject([]) { |array, value|
124   - if value.is_a?(::Hash)
125   - array += value[match.to_s] if value[match.to_s]
126   - else
127   - array << value
128   - end
129   - array
130   - }.uniq.collect(&:to_sym)
131   - end
132   -
133   - def gemset_from_loaded_specs
134   - if defined?(Gem)
135   - Gem.loaded_specs.each do |name, spec|
136   - if name == gemspec.name
137   - return :default
138   - elsif name[0..gemspec.name.length] == "#{gemspec.name}-"
139   - return name[gemspec.name.length+1..-1].to_sym
140   - end
141   - end
142   - :default
143   - else
144   - :none
145   - end
146   - end
147   -
148   - def symbolize_keys(hash)
149   - return {} unless hash.is_a?(::Hash)
150   - hash.inject({}) do |options, (key, value)|
151   - value = symbolize_keys(value) if value.is_a?(::Hash)
152   - options[(key.to_sym rescue key) || key] = value
153   - options
154   - end
155   - end
156   - end
157   - end
158   - end
159   -end
249 spec/cap_reserve/gems_spec.rb
... ... @@ -1,249 +0,0 @@
1   -require 'spec_helper'
2   -
3   -describe CapReserve::Gems do
4   -
5   - before(:each) do
6   - @old_config = CapReserve::Gems.config
7   -
8   - CapReserve::Gems.config.gemspec = "#{$root}/spec/fixtures/gemspec.yml"
9   - CapReserve::Gems.config.gemsets = [
10   - "#{$root}/spec/fixtures/gemsets.yml"
11   - ]
12   - CapReserve::Gems.config.warn = true
13   -
14   - CapReserve::Gems.gemspec true
15   - CapReserve::Gems.gemset = nil
16   - end
17   -
18   - after(:each) do
19   - CapReserve::Gems.config = @old_config
20   - end
21   -
22   - describe :activate do
23   - it "should activate gems" do
24   - CapReserve::Gems.stub!(:gem)
25   - CapReserve::Gems.should_receive(:gem).with('rspec', '=1.3.1')
26   - CapReserve::Gems.should_receive(:gem).with('rake', '=0.8.7')
27   - CapReserve::Gems.activate :rspec, 'rake'
28   - end
29   - end
30   -
31   - describe :gemset= do
32   - before(:each) do
33   - CapReserve::Gems.config.gemsets = [
34   - {
35   - :name => {
36   - :rake => '>0.8.6',
37   - :default => {
38   - :externals => '=1.0.2'
39   - }
40   - }
41   - },
42   - "#{$root}/spec/fixtures/gemsets.yml"
43   - ]
44   - end
45   -
46   - describe :default do
47   - before(:each) do
48   - CapReserve::Gems.gemset = :default
49   - end
50   -
51   - it "should set @gemset" do
52   - CapReserve::Gems.gemset.should == :default
53   - end
54   -
55   - it "should set @gemsets" do
56   - CapReserve::Gems.gemsets.should == {
57   - :name => {
58   - :rake => ">0.8.6",
59   - :default => {
60   - :externals => '=1.0.2',
61   - :mysql => "=2.8.1",
62   - :rspec => "=1.3.1"
63   - },
64   - :rspec2 => {
65   - :mysql2 => "=0.2.6",
66   - :rspec => "=2.3.0"
67   - },
68   - :solo => nil
69   - }
70   - }
71   - end
72   -
73   - it "should set Gems.versions" do
74   - CapReserve::Gems.versions.should == {
75   - :externals => "=1.0.2",
76   - :mysql => "=2.8.1",
77   - :rake => ">0.8.6",
78   - :rspec => "=1.3.1"
79   - }
80   - end
81   -
82   - it "should return proper values for Gems.dependencies" do
83   - CapReserve::Gems.dependencies.should == [ :rake, :mysql ]
84   - CapReserve::Gems.development_dependencies.should == []
85   - end
86   -
87   - it "should return proper values for Gems.gemset_names" do
88   - CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
89   - end
90   - end
91   -
92   - describe :rspec2 do
93   - before(:each) do
94   - CapReserve::Gems.gemset = "rspec2"
95   - end
96   -
97   - it "should set @gemset" do
98   - CapReserve::Gems.gemset.should == :rspec2
99   - end
100   -
101   - it "should set @gemsets" do
102   - CapReserve::Gems.gemsets.should == {
103   - :name => {
104   - :rake => ">0.8.6",
105   - :default => {
106   - :externals => '=1.0.2',
107   - :mysql => "=2.8.1",
108   - :rspec => "=1.3.1"
109   - },
110   - :rspec2 => {
111   - :mysql2=>"=0.2.6",
112   - :rspec => "=2.3.0"
113   - },
114   - :solo => nil
115   - }
116   - }
117   - end
118   -
119   - it "should set Gems.versions" do
120   - CapReserve::Gems.versions.should == {
121   - :mysql2 => "=0.2.6",
122   - :rake => ">0.8.6",
123   - :rspec => "=2.3.0"
124   - }
125   - end
126   -
127   - it "should return proper values for Gems.dependencies" do
128   - CapReserve::Gems.dependencies.should == [ :rake, :mysql2 ]
129   - CapReserve::Gems.development_dependencies.should == []
130   - end
131   -
132   - it "should return proper values for Gems.gemset_names" do
133   - CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
134   - end
135   - end
136   -
137   - describe :solo do
138   - before(:each) do
139   - CapReserve::Gems.gemset = :solo
140   - end
141   -
142   - it "should set @gemset" do
143   - CapReserve::Gems.gemset.should == :solo
144   - end
145   -
146   - it "should set @gemsets" do
147   - CapReserve::Gems.gemsets.should == {
148   - :name => {
149   - :rake => ">0.8.6",
150   - :default => {
151   - :externals => '=1.0.2',
152   - :mysql => "=2.8.1",
153   - :rspec => "=1.3.1"
154   - },
155   - :rspec2 => {
156   - :mysql2=>"=0.2.6",
157   - :rspec => "=2.3.0"
158   - },
159   - :solo => nil
160   - }
161   - }
162   - end
163   -
164   - it "should set Gems.versions" do
165   - CapReserve::Gems.versions.should == {:rake=>">0.8.6"}
166   - end
167   -
168   - it "should return proper values for Gems.dependencies" do
169   - CapReserve::Gems.dependencies.should == [:rake]
170   - CapReserve::Gems.development_dependencies.should == []
171   - end
172   -
173   - it "should return proper values for Gems.gemset_names" do
174   - CapReserve::Gems.gemset_names.should == [ :default, :rspec2, :solo ]
175   - end
176   - end
177   -
178   - describe :nil do
179   - before(:each) do
180   - CapReserve::Gems.gemset = nil
181   - end
182   -
183   - it "should set everything to nil" do
184   - CapReserve::Gems.gemset.should == nil
185   - CapReserve::Gems.gemsets.should == nil
186   - CapReserve::Gems.versions.should == nil
187   - end
188   - end
189   - end
190   -
191   - describe :gemset_from_loaded_specs do
192   - before(:each) do
193   - Gem.stub!(:loaded_specs)
194   - end
195   -
196   - it "should return the correct gemset for name gem" do
197   - Gem.should_receive(:loaded_specs).and_return({ "name" => nil })
198   - CapReserve::Gems.send(:gemset_from_loaded_specs).should == :default
199   - end
200   -
201   - it "should return the correct gemset for name-rspec gem" do
202   - Gem.should_receive(:loaded_specs).and_return({ "name-rspec2" => nil })
203   - CapReserve::Gems.send(:gemset_from_loaded_specs).should == :rspec2
204   - end
205   - end
206   -
207   - describe :reload_gemspec do
208   - it "should populate @gemspec" do
209   - CapReserve::Gems.gemspec.hash.should == {
210   - "name" => "name",
211   - "version" => "0.1.0",
212   - "authors" => ["Author"],
213   - "email" => "email@email.com",
214   - "homepage" => "http://github.com/author/name",
215   - "summary" => "Summary",
216   - "description" => "Description",
217   - "dependencies" => [
218   - "rake",
219   - { "default" => [ "mysql" ] },
220   - { "rspec2" => [ "mysql2" ] }
221   - ],
222   - "development_dependencies" => nil
223   - }
224   - end
225   -
226   - it "should create methods from keys of @gemspec" do
227   - CapReserve::Gems.gemspec.name.should == "name"
228   - CapReserve::Gems.gemspec.version.should == "0.1.0"
229   - CapReserve::Gems.gemspec.authors.should == ["Author"]
230   - CapReserve::Gems.gemspec.email.should == "email@email.com"
231   - CapReserve::Gems.gemspec.homepage.should == "http://github.com/author/name"
232   - CapReserve::Gems.gemspec.summary.should == "Summary"
233   - CapReserve::Gems.gemspec.description.should == "Description"
234   - CapReserve::Gems.gemspec.dependencies.should == [
235   - "rake",
236   - { "default" => ["mysql"] },
237   - { "rspec2" => [ "mysql2" ] }
238   - ]
239   - CapReserve::Gems.gemspec.development_dependencies.should == nil
240   - end
241   -
242   - it "should produce a valid gemspec" do
243   - CapReserve::Gems.gemset = :default
244   - gemspec = File.expand_path("../../../cap_reserve.gemspec", __FILE__)
245   - gemspec = eval(File.read(gemspec), binding, gemspec)
246   - gemspec.validate.should == true
247   - end
248   - end
249   -end
9 spec/fixtures/gemsets.yml
... ... @@ -1,9 +0,0 @@
1   -name:
2   - rake: =0.8.7
3   - default:
4   - mysql: =2.8.1
5   - rspec: =1.3.1
6   - rspec2:
7   - mysql2: =0.2.6
8   - rspec: =2.3.0
9   - solo: null
15 spec/fixtures/gemspec.yml
... ... @@ -1,15 +0,0 @@
1   -name: name
2   -version: 0.1.0
3   -authors:
4   - - Author
5   -email: email@email.com
6   -homepage: http://github.com/author/name
7   -summary: Summary
8   -description: Description
9   -dependencies:
10   - - rake
11   - - default:
12   - - mysql
13   - - rspec2:
14   - - mysql2
15   -development_dependencies: null
13 spec/spec_helper.rb
... ... @@ -1,11 +1,8 @@
1   -require 'pp'
  1 +require "pp"
  2 +require "bundler"
2 3
3   -$root = File.expand_path('../../', __FILE__)
4   -require "#{$root}/lib/cap_reserve/gems"
5   -
6   -CapReserve::Gems.activate :rspec
  4 +Bundler.require(:development)
7 5
8   -require "#{$root}/lib/cap_reserve"
  6 +$root = File.expand_path('../../', __FILE__)
9 7
10   -Spec::Runner.configure do |config|
11   -end
  8 +require "#{$root}/lib/cap_reserve"

0 comments on commit 67c8bc3

Please sign in to comment.
Something went wrong with that request. Please try again.