Sha256: 968642c233fe6baa0332d23d44c689d66a388d2b449c586f0ff1e16b45ec0f0b

Contents?: true

Size: 853 Bytes

Versions: 5

Compression:

Stored size: 853 Bytes

Contents

module Rubolite
  class Writer
    attr_accessor :write_path
    attr_reader :parser

    def initialize(parser)
      @parser = parser
      @write_path = parser.conf_file
    end

    def write!
      File.open(write_path, "w") do |handler|
        handler.write groups
        handler.write repos
      end
    end

    def groups
      parser.groups.each_with_object([]) do |(name, users), lines|
        lines << "@#{name} = #{users.join(" ")}"
      end.join("\n") + "\n\n"
    end

    def repos
      parser.repos.each_with_object([]) do |repo, blocks|
        blocks << repo_block(repo)
      end.join("\n\n") + "\n"
    end

    def repo_block(repo)
      lines = []
      lines << "repo #{repo.name}"
      repo.users.each do |user|
        lines << "    #{user.permissions} = #{user.name}"
      end

      lines.join("\n")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubolite-0.0.6 lib/rubolite/writer.rb
rubolite-0.0.5 lib/rubolite/writer.rb
rubolite-0.0.4 lib/rubolite/writer.rb
rubolite-0.0.3 lib/rubolite/writer.rb
rubolite-0.0.2 lib/rubolite/writer.rb