Sha256: 257675f02807f368e170ec3ec8eb8d4fe380cd7d371db5a4316c688b50e42838

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module OrganizeGemfile
  class Builder
    attr_accessor :lines

    def initialize(gemfile_path, ruby_version:, groups:)
      @gemfile_path = gemfile_path
      @ruby_version = ruby_version
      @groups = groups
      new_gemfile_code = build
    end

    def build
      lines = []
      lines << "source \"https://rubygems.org\""
      lines << "git_source(:github) { |repo| \"https://github.com/\#{repo}.git\" }"
      lines << ""
      lines << "ruby \"#{@ruby_version}\""
      lines << ""

      before_default_group = @groups["before_default"]
      if before_default_group
        lines << before_default_group.to_gemfile_lines
        lines << ""
      end

      default_group = @groups["default"]
      if default_group
        lines << default_group.to_gemfile_lines
        lines << ""
      end

      @groups.select { |name, _group| name != "before_default" && name != "default" }.each do |_name, group|
        lines << group.to_gemfile_lines
        lines << ""
      end

      lines.join("\n")
    end

    def available_groups
      @groups.keys
    end

    def default_group
      @groups["default"]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
organize_gemfile-0.1.1 lib/organize_gemfile/builder.rb
organize_gemfile-0.1.0 lib/organize_gemfile/builder.rb