Class: Decommission
- Inherits:
-
Object
- Object
- Decommission
- Defined in:
- lib/decommission.rb,
lib/decommission/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
- .detect(path = Dir.pwd) ⇒ Object
- .detect_bundled_version(folder) ⇒ Object
- .detect_env_version(folder) ⇒ Object
- .gemfile_present?(folder) ⇒ Boolean
- .rails_app?(folder) ⇒ Boolean
Class Method Details
.detect(path = Dir.pwd) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/decommission.rb', line 6 def self.detect(path = Dir.pwd) folders = Dir.glob('*') max_length = folders.max_by(&:length).length any_rails_apps = false folders.each do |folder| if rails_app?(folder) any_rails_apps = true if gemfile_present?(folder) version = detect_bundled_version(folder) puts "#{folder.ljust(max_length)} #{version}".green if version else version = detect_env_version(folder) puts "#{folder.ljust(max_length)} #{version}".red if version end end end puts "No rails apps found, run this in your code directory".red unless any_rails_apps end |
.detect_bundled_version(folder) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/decommission.rb', line 35 def self.detect_bundled_version(folder) Dir.chdir folder do deps = Bundler::Definition.build('Gemfile', 'Gemfile.lock', {}).dependencies rails = deps.select{|s| s.name == 'rails' }.first rails.requirement if rails end end |
.detect_env_version(folder) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/decommission.rb', line 43 def self.detect_env_version(folder) env_path = File.join(folder, 'config', 'environment.rb') env = open env_path env.each_line do |line| match = line.match(/RAILS_GEM_VERSION = ['"](.+)['"]/) return "= #{match[1]}" if match end return 'unknown (pre 3.0)' end |
.gemfile_present?(folder) ⇒ Boolean
30 31 32 33 |
# File 'lib/decommission.rb', line 30 def self.gemfile_present?(folder) gemfile_path = File.join(folder, 'Gemfile') File.exists?(gemfile_path) end |
.rails_app?(folder) ⇒ Boolean
25 26 27 28 |
# File 'lib/decommission.rb', line 25 def self.rails_app?(folder) env_path = File.join(folder, 'config', 'environment.rb') File.exists?(env_path) end |