Sha256: 5baf946a21f4c7f9a41348bd7977cbee010fbb1338525a4b9f259932af719ecb

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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
      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

1 entries across 1 versions & 1 rubygems

Version Path
organize_gemfile-0.1.2 lib/organize_gemfile/builder.rb