Class: Suspenders::Cleanup::OrganizeGemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/suspenders/cleanup/organize_gemfile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gemfile) ⇒ OrganizeGemfile

Returns a new instance of OrganizeGemfile.



11
12
13
14
15
16
17
18
19
20
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 11

def initialize(gemfile)
  @gemfile = gemfile

  @current_lines = File.read(gemfile).lines
  @new_lines = []
  @new_line_markers = []

  @current_group = nil
  @gem_groups = {}
end

Instance Attribute Details

#current_groupObject (readonly)

Returns the value of attribute current_group.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def current_group
  @current_group
end

#current_linesObject (readonly)

Returns the value of attribute current_lines.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def current_lines
  @current_lines
end

#gem_groupsObject (readonly)

Returns the value of attribute gem_groups.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def gem_groups
  @gem_groups
end

#gemfileObject (readonly)

Returns the value of attribute gemfile.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def gemfile
  @gemfile
end

#new_line_markersObject (readonly)

Returns the value of attribute new_line_markers.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def new_line_markers
  @new_line_markers
end

#new_linesObject (readonly)

Returns the value of attribute new_lines.



8
9
10
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 8

def new_lines
  @new_lines
end

Class Method Details

.perform(gemfile) ⇒ Object



4
5
6
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 4

def self.perform(gemfile)
  new(gemfile).perform
end

Instance Method Details

#performObject



22
23
24
25
26
27
28
29
30
# File 'lib/suspenders/cleanup/organize_gemfile.rb', line 22

def perform
  remove_line_breaks
  sort_gems_and_groups
  add_gem_groups_to_gemfile
  add_line_breaks
  cleanup

  File.open(gemfile, "w+") { _1.write new_lines.join }
end