gemfiler 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/Gemfiler/cli.rb CHANGED
@@ -2,8 +2,9 @@ require 'awesome_print'
2
2
 
3
3
  module Gemfiler
4
4
  class CLI < Thor
5
- desc 'file', 'Organizes your Gemfile.'
6
5
 
6
+ desc 'file', 'Organizes your Gemfile.'
7
+ method_options nice_spaces: :boolean, ruby19_hashes: :boolean
7
8
  def file(gemfile='Gemfile')
8
9
  gemfile = "#{Dir.pwd}/#{gemfile}"
9
10
 
@@ -13,7 +14,7 @@ module Gemfiler
13
14
  filer = Gemfiler::Filer.new(cabinet)
14
15
  filer.group
15
16
  filer.alphabetize
16
- output = Gemfiler::Output.new(filer)
17
+ output = Gemfiler::Output.new(filer, options)
17
18
 
18
19
  output.write(gemfile)
19
20
  end
@@ -2,10 +2,11 @@ require 'erb'
2
2
 
3
3
  module Gemfiler
4
4
  class Output
5
- attr_reader :filer
5
+ attr_reader :filer, :options
6
6
 
7
- def initialize(filer)
8
- @filer = filer
7
+ def initialize(filer, options={})
8
+ @filer = filer
9
+ @options = options
9
10
  end
10
11
 
11
12
  def write(gemfile)
@@ -34,8 +35,8 @@ module Gemfiler
34
35
  parts = []
35
36
  if version_info = filer.shim.ruby_version
36
37
  parts << "ruby '#{version_info[:version]}'"
37
- parts << ":engine => '#{version_info[:engine]}'" if version_info[:engine]
38
- parts << ":engine_version => '#{version_info[:engine_version]}'" if version_info[:engine_version]
38
+ parts << hash_keyvalue(:engine, version_info[:engine]) if version_info[:engine]
39
+ parts << hash_keyvalue(:engine_version, version_info[:engine_version]) if version_info[:engine_version]
39
40
  end
40
41
 
41
42
  parts.join(', ')
@@ -49,8 +50,9 @@ module Gemfiler
49
50
  end
50
51
 
51
52
  def longest_gem_name(group=nil)
53
+ @longest ||= {}
52
54
  gems = group ? groups[group] : filer.uncategorized
53
- gems.inject(0) {|max, gem| gem[:name].length > max ? gem[:name].length : max }
55
+ @longest[group] ||= gems.inject(0) {|max, gem| gem[:name].length > max ? gem[:name].length : max }
54
56
  end
55
57
 
56
58
  def groups
@@ -72,19 +74,27 @@ module Gemfiler
72
74
  end
73
75
  end
74
76
 
77
+ def hash_keyvalue(key, value)
78
+ if @options[:ruby19_hashes]
79
+ "#{key.to_s}: #{type_value(value)}"
80
+ else
81
+ "#{type_value(key)} => #{type_value(value)}"
82
+ end
83
+ end
84
+
75
85
  # It's a short parameter name because my syntax highlighter doesn't like the word "gem"
76
86
  def gem_line(g, groups=nil)
77
87
  gem_name = g[:name]
78
- line = ["gem '#{gem_name}'"]
88
+ line = ["gem '#{gem_name}'"]
79
89
 
80
- space_between = longest_gem_name(groups) - gem_name.length
90
+ space_between = @options[:nice_spaces] ? longest_gem_name(groups) - gem_name.length : 0
81
91
 
82
92
  if g[:version]
83
93
  line << (' ' * space_between) + "'#{g[:version]}'"
84
94
  elsif (g.length - 1) > 0
85
95
  line << (' ' * space_between) + g.inject([]) do |options, (key, value)|
86
96
  if key != :name
87
- options << ":#{key} => #{type_value(value)}"
97
+ options << hash_keyvalue(key, value)
88
98
  end
89
99
 
90
100
  options
@@ -1,3 +1,3 @@
1
1
  module Gemfiler
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: