Class: Gemfiler::Output
- Inherits:
-
Object
- Object
- Gemfiler::Output
- Defined in:
- lib/Gemfiler/output.rb
Instance Attribute Summary collapse
-
#filer ⇒ Object
readonly
Returns the value of attribute filer.
Instance Method Summary collapse
- #content ⇒ Object
-
#gem_line(g, groups = nil) ⇒ Object
It’s a short parameter name because my syntax highlighter doesn’t like the word “gem”.
- #gemspec ⇒ Object
- #groups ⇒ Object
-
#initialize(filer) ⇒ Output
constructor
A new instance of Output.
- #longest_gem_name(group = nil) ⇒ Object
- #ruby ⇒ Object
- #sources ⇒ Object
- #spacer ⇒ Object
- #type_value(value) ⇒ Object
- #uncategorized_gems ⇒ Object
- #write(gemfile) ⇒ Object
Constructor Details
#initialize(filer) ⇒ Output
Returns a new instance of Output.
7 8 9 |
# File 'lib/Gemfiler/output.rb', line 7 def initialize(filer) @filer = filer end |
Instance Attribute Details
#filer ⇒ Object (readonly)
Returns the value of attribute filer.
5 6 7 |
# File 'lib/Gemfiler/output.rb', line 5 def filer @filer end |
Instance Method Details
#content ⇒ Object
17 18 19 20 |
# File 'lib/Gemfiler/output.rb', line 17 def content erb = ERB.new(File.read(File.('../templates/gemfile.erb', __FILE__)), nil, '<>') erb.result(binding) end |
#gem_line(g, groups = nil) ⇒ Object
It’s a short parameter name because my syntax highlighter doesn’t like the word “gem”
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/Gemfiler/output.rb', line 76 def gem_line(g, groups=nil) gem_name = g[:name] line = ["gem '#{gem_name}'"] space_between = longest_gem_name(groups) - gem_name.length if g[:version] line << (' ' * space_between) + "'#{g[:version]}'" elsif (g.length - 1) > 0 line << (' ' * space_between) + g.inject([]) do |, (key, value)| if key != :name << ":#{key} => #{type_value(value)}" end end.join(', ') end line.join(', ') end |
#gemspec ⇒ Object
29 30 31 |
# File 'lib/Gemfiler/output.rb', line 29 def gemspec filer.shim.gemspec? ? 'gemspec' : '' end |
#groups ⇒ Object
56 57 58 |
# File 'lib/Gemfiler/output.rb', line 56 def groups filer.groups end |
#longest_gem_name(group = nil) ⇒ Object
51 52 53 54 |
# File 'lib/Gemfiler/output.rb', line 51 def longest_gem_name(group=nil) gems = group ? groups[group] : filer.uncategorized gems.inject(0) {|max, gem| gem[:name].length > max ? gem[:name].length : max } end |
#ruby ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/Gemfiler/output.rb', line 33 def ruby parts = [] if version_info = filer.shim.ruby_version parts << "ruby '#{version_info[:version]}'" parts << ":engine => '#{version_info[:engine]}'" if version_info[:engine] parts << ":engine_version => '#{version_info[:engine_version]}'" if version_info[:engine_version] end parts.join(', ') end |
#sources ⇒ Object
22 23 24 25 26 27 |
# File 'lib/Gemfiler/output.rb', line 22 def sources filer.shim.sources.inject([]) do |sources, source| sources << "source #{type_value(source)}" sources end end |
#spacer ⇒ Object
60 61 62 |
# File 'lib/Gemfiler/output.rb', line 60 def spacer ' ' end |
#type_value(value) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/Gemfiler/output.rb', line 64 def type_value(value) case value when Symbol ":#{value.to_s}" when String "'#{value}'" when Fixnum, TrueClass, FalseClass value.to_s end end |
#uncategorized_gems ⇒ Object
44 45 46 47 48 49 |
# File 'lib/Gemfiler/output.rb', line 44 def uncategorized_gems filer.uncategorized.inject([]) do |gems, gem| gems << self.gem_line(gem) gems end end |
#write(gemfile) ⇒ Object
11 12 13 14 15 |
# File 'lib/Gemfiler/output.rb', line 11 def write(gemfile) File.open(gemfile, 'w') do |file| file.write(content) end end |