Sha256: f1aa2881ae64c0eed2b970c1a261d95245dfe378e7e0d2ac7fdcf13079bcf746
Contents?: true
Size: 1.6 KB
Versions: 1
Compression:
Stored size: 1.6 KB
Contents
module OrganizeGemfile class GemfileGroup < Struct.new(:name, :specs) def initialize(name, specs = []) super end 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
organize_gemfile-0.1.1 | lib/organize_gemfile/gemfile_group.rb |