decommission 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in decommission.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andrew Nesbitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Decommission
2
+
3
+ Quickly discover which versions of rails all your apps are running
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ $ gem install decommission
10
+
11
+ ## Usage
12
+
13
+ Change into your code directory:
14
+
15
+ $ cd ~/code
16
+
17
+ And run decommission
18
+
19
+ $ decommission
20
+
21
+ ## Development
22
+
23
+ Source hosted at [GitHub](http://github.com/andrew/decommission).
24
+ Report Issues/Feature requests on [GitHub Issues](http://github.com/andrew/decommission/issues).
25
+
26
+ ### Note on Patches/Pull Requests
27
+
28
+ * Fork the project.
29
+ * Make your feature addition or bug fix.
30
+ * Add tests for it. This is important so I don't break it in a
31
+ future version unintentionally.
32
+ * Commit, do not mess with rakefile, version, or history.
33
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
34
+ * Send me a pull request. Bonus points for topic branches.
35
+
36
+ ## Copyright
37
+
38
+ Copyright (c) 2012 Andrew Nesbitt. See [LICENSE](https://github.com/andrew/decommission/blob/master/LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/decommission ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'decommission'
4
+ Decommission.detect
5
+
6
+ # needs a proper command line parser, version, help etc
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/decommission/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrew Nesbitt"]
6
+ gem.email = ["andrewnez@gmail.com"]
7
+ gem.description = %q{Quickly discover which versions of rails all your apps are running}
8
+ gem.summary = %q{Detect old rails apps}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "decommission"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Decommission::VERSION
17
+
18
+ gem.add_runtime_dependency("bundler")
19
+ gem.add_runtime_dependency("colorize")
20
+ gem.add_runtime_dependency("trollop")
21
+ end
@@ -0,0 +1,53 @@
1
+ require "decommission/version"
2
+ require 'bundler'
3
+ require 'colorize'
4
+
5
+ class Decommission
6
+ def self.detect(path = Dir.pwd)
7
+ folders = Dir.glob('*')
8
+ max_length = folders.max_by(&:length).length
9
+ any_rails_apps = false
10
+ folders.each do |folder|
11
+ if rails_app?(folder)
12
+ any_rails_apps = true
13
+ if gemfile_present?(folder)
14
+ version = detect_bundled_version(folder)
15
+ puts "#{folder.ljust(max_length)} #{version}".green
16
+ else
17
+ version = detect_env_version(folder)
18
+ puts "#{folder.ljust(max_length)} #{version}".red
19
+ end
20
+ end
21
+ end
22
+ puts "No rails apps found, run this in your code directory".red unless any_rails_apps
23
+ end
24
+
25
+ def self.rails_app?(folder)
26
+ env_path = File.join(folder, 'config', 'environment.rb')
27
+ File.exists?(env_path)
28
+ end
29
+
30
+ def self.gemfile_present?(folder)
31
+ gemfile_path = File.join(folder, 'Gemfile')
32
+ File.exists?(gemfile_path)
33
+ end
34
+
35
+ def self.detect_bundled_version(folder)
36
+ Dir.chdir folder do
37
+ deps = Bundler::Definition.build('Gemfile', 'Gemfile.lock', {}).dependencies
38
+ rails = deps.select{|s| s.name == 'rails' }.first
39
+ rails.requirement
40
+ end
41
+ end
42
+
43
+ def self.detect_env_version(folder)
44
+ env_path = File.join(folder, 'config', 'environment.rb')
45
+ env = open env_path
46
+
47
+ env.each_line do |line|
48
+ match = line.match(/RAILS_GEM_VERSION = ['"](.+)['"]/)
49
+ return "= #{match[1]}" if match
50
+ end
51
+ return 'unknown (pre 3.0)'
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ class Decommission
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decommission
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Nesbitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70140990714000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70140990714000
25
+ - !ruby/object:Gem::Dependency
26
+ name: colorize
27
+ requirement: &70140990713440 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70140990713440
36
+ - !ruby/object:Gem::Dependency
37
+ name: trollop
38
+ requirement: &70140990712860 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70140990712860
47
+ description: Quickly discover which versions of rails all your apps are running
48
+ email:
49
+ - andrewnez@gmail.com
50
+ executables:
51
+ - decommission
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/decommission
61
+ - decommission.gemspec
62
+ - lib/decommission.rb
63
+ - lib/decommission/version.rb
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.6
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Detect old rails apps
88
+ test_files: []