Class: GemfileArranger::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/gemfile_arranger/cli.rb

Instance Method Summary collapse

Instance Method Details

#arrangeObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gemfile_arranger/cli.rb', line 39

def arrange
  code = gemfile_contents(options[:gemfile])

  buffer        = Parser::Source::Buffer.new('(gemfile_arranger arrange)')
  buffer.source = code
  parser        = Parser::CurrentRuby.new
  ast           = parser.parse(buffer)

  sort_gems_in_group = Traverse::SortGemsInGroup.new
  rewrited_ast = sort_gems_in_group.process(ast)

  sort_priority_gems_in_group = Traverse::SortPriorityGemsInGroup.new(config['priority_gem'])
  rewrited_ast = sort_priority_gems_in_group.process(rewrited_ast)

  sort_block = Traverse::SortBlock.new(config['block_order'])
  rewrited_ast = sort_block.process(rewrited_ast)

  rewrited_gemfile = Unparser.unparse(rewrited_ast)
  if options[:auto_correct]
    rewrite_gemfile(rewrited_gemfile, options[:gemfile])
    puts "Rewrite Gemfile compete! #{options[:gemfile]}"
  else
    puts rewrited_gemfile
  end
end

#show_base_configObject



71
72
73
# File 'lib/gemfile_arranger/cli.rb', line 71

def show_base_config
  puts YAML.dump(base_config)
end

#show_configObject



66
67
68
# File 'lib/gemfile_arranger/cli.rb', line 66

def show_config
  puts YAML.dump(config)
end

#versionObject



31
32
33
# File 'lib/gemfile_arranger/cli.rb', line 31

def version
  puts "Gemfile Arranger version #{VERSION}"
end