lib/eefgilm/gemfile.rb in eefgilm-1.1.2 vs lib/eefgilm/gemfile.rb in eefgilm-1.2.0
- old
+ new
@@ -1,16 +1,16 @@
module Eefgilm
class Gemfile
attr_accessor :path, :source, :groups, :rubyversion
- def initialize(path = ".", options = {})
- @path = path
- @groups ={}
+ def initialize(path = '.', options = {})
+ @path = path
+ @groups = {}
@options = {
- :alphabetize => true,
- :delete_whitespace => true,
- :delete_comments => true
+ alphabetize: true,
+ delete_whitespace: true,
+ delete_comments: true
}.merge(options)
end
def clean!
# Extract:
@@ -27,18 +27,18 @@
end
private
def extract_to_array_of_lines
- gemfile = File.open("#{@path}/Gemfile", "r+")
+ gemfile = File.open("#{@path}/Gemfile", 'r+')
group_block = :all
file_lines = gemfile.readlines
file_lines.each do |line|
self.source = line if line.match(/^source/)
- if self.source == "source 'http://rubygems.org'\n"
+ if source == "source 'http://rubygems.org'\n"
self.source = "source 'https://rubygems.org'\n"
end
self.rubyversion = line if line.match(/^ruby/)
@@ -47,37 +47,37 @@
elsif line.match(/^\s*end/)
group_block = :all
end
if line.match(/^\s*gem/)
- if self.groups[group_block].nil?
- self.groups[group_block] = [line]
+ if groups[group_block].nil?
+ groups[group_block] = [line]
else
- self.groups[group_block] << line
+ groups[group_block] << line
end
end
end
end
def change_double_qoutes_to_single
@groups.each do |group, gems|
@groups[group] = gems.map do |g|
- g.gsub('"',"'")
+ g.tr("\"", "'")
end
end
end
def delete_comments!
@groups.each do |group, gems|
@groups[group] = gems.map do |g|
- g.gsub(/#(.*)$/, "")
+ g.gsub(/#(.*)$/, '')
end
end
end
def recreate_file
- output = File.open( "#{@path}/Gemfile", "w+" )
+ output = File.open("#{@path}/Gemfile", 'w+')
output.puts [@source, @rubyversion].compact
output.puts
@groups.each do |group, gems|
if group == :all
@@ -89,11 +89,11 @@
output.puts "group #{group}"
gems.each do |g|
output.puts " #{g}"
end
- output.puts "end"
+ output.puts 'end'
end
end
output.close
end
@@ -105,10 +105,10 @@
end
def delete_whitespace!
@groups.each do |group, gems|
@groups[group] = gems.map do |g|
- g.gsub(/(?<=^|\[)\s+|\s+(?=$|\])|(?<=\s)\s+/, "")
+ g.gsub(/(?<=^|\[)\s+|\s+(?=$|\])|(?<=\s)\s+/, '')
end
end
end
end
end