Module: OrganizeGemfile
- Defined in:
- lib/organize_gemfile.rb,
lib/organize_gemfile/builder.rb,
lib/organize_gemfile/version.rb,
lib/organize_gemfile/bundle_parser.rb,
lib/organize_gemfile/gemfile_group.rb
Defined Under Namespace
Classes: Builder, BundleParser, Error, GemfileGroup
Constant Summary
collapse
- VERSION =
"0.1.1"
Class Method Summary
collapse
Class Method Details
.execute(*args) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/organize_gemfile.rb', line 13
def self.execute(*args)
options = parse_options(args)
gemfile_path = options[:gemfile] ||= File.expand_path('Gemfile')
unless File.exist?(gemfile_path)
puts "Gemfile not found at #{gemfile_path}"
return
end
gemfile_lock_path = Pathname.new(gemfile_path).parent.join('Gemfile.lock')
unless gemfile_lock_path.exist?
puts "Gemfile.lock not found at #{gemfile_lock_path}. Be sure to run `bundle install` before running this command."
return
end
gemfile_lock_path = File.expand_path('Gemfile.lock')
raise 'Gemfile.lock not found' unless File.exist?(gemfile_lock_path)
parser = BundleParser.new(gemfile_path, gemfile_lock_path)
ruby_version = parser.ruby_version
groups = parser.groups
builder =
Builder.new(gemfile_path, ruby_version: ruby_version, groups: groups)
revised_gemfile = builder.build
File.open(gemfile_path, 'w') { |f| f.write(revised_gemfile) }
puts 'Gemfile organized!'
end
|
.parse_options(args) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/organize_gemfile.rb', line 43
def self.parse_options(args)
options = {}
opts = OptionParser.new
opts.banner = 'Usage: organize_gemfile [options]'
opts.on('-h', '--help', 'Prints this help') do
puts opts
exit
end
opts.on('-gPATH', '--gemfile=PATH', 'Path to Gemfile') do |path|
options[:gemfile] = File.expand_path(path)
end
opts.parse!(into: options)
options
end
|