Class: Rubolite::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/rubolite/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ Writer

Returns a new instance of Writer.



6
7
8
9
# File 'lib/rubolite/writer.rb', line 6

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

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



4
5
6
# File 'lib/rubolite/writer.rb', line 4

def parser
  @parser
end

#write_pathObject

Returns the value of attribute write_path.



3
4
5
# File 'lib/rubolite/writer.rb', line 3

def write_path
  @write_path
end

Instance Method Details

#groupsObject



18
19
20
21
22
# File 'lib/rubolite/writer.rb', line 18

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

#repo_block(repo) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rubolite/writer.rb', line 30

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

  lines.join("\n")
end

#reposObject



24
25
26
27
28
# File 'lib/rubolite/writer.rb', line 24

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

#write!Object



11
12
13
14
15
16
# File 'lib/rubolite/writer.rb', line 11

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