Class: OrganizeGemfile::GemfileGroup
- Inherits:
-
Struct
- Object
- Struct
- OrganizeGemfile::GemfileGroup
- Defined in:
- lib/organize_gemfile/gemfile_group.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#specs ⇒ Object
Returns the value of attribute specs.
Instance Method Summary collapse
-
#initialize(name, specs = []) ⇒ GemfileGroup
constructor
A new instance of GemfileGroup.
- #to_gemfile_lines ⇒ Object
Constructor Details
permalink #initialize(name, specs = []) ⇒ GemfileGroup
Returns a new instance of GemfileGroup.
3 4 5 |
# File 'lib/organize_gemfile/gemfile_group.rb', line 3 def initialize(name, specs = []) super end |
Instance Attribute Details
permalink #name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/organize_gemfile/gemfile_group.rb', line 2 def name @name end |
permalink #specs ⇒ Object
Returns the value of attribute specs
2 3 4 |
# File 'lib/organize_gemfile/gemfile_group.rb', line 2 def specs @specs end |
Instance Method Details
permalink #to_gemfile_lines ⇒ Object
[View source]
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/organize_gemfile/gemfile_group.rb', line 7 def to_gemfile_lines lines = [] indent_spaces = "" max_length = 0 is_before_default = name == :before_default is_default = name == [:default] if !is_before_default && !is_default indent_spaces = " " lines << "group #{name.map { |n| ":#{n}" }.join(", ")} do" end spec_lines = specs.sort_by { |s| s[:name] }.map do |spec| parts = [] parts << "gem \"#{spec[:name]}\"" if spec[:version] && spec[:version] != ">= 0" version_parts = [] spec[:version].split(",").each do |version| version_parts << "\"#{version.strip}\"" end parts << version_parts.join(", ") end parts << "require: \"#{spec[:requires].first}\"" if spec[:requires].first && spec[:requires].first != spec[:name] parts << "require: false" if spec[:requires] == [] parts << "platforms: %i[ #{spec[:platforms].join(" ")} ]" if spec[:platforms].any? line = parts.join(", ") if spec[:summary] max_length = [max_length, line.length].max end {line: line, spec: spec} end spec_lines.each do |l| line = l[:line] spec = l[:spec] if spec[:summary] line = line.ljust(max_length) line += " # #{spec[:summary]}" end lines << indent_spaces + line end if !is_before_default && !is_default lines << "end" end lines end |