Class: Rubolite::Writer
- Inherits:
-
Object
- Object
- Rubolite::Writer
- Defined in:
- lib/rubolite/writer.rb
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#write_path ⇒ Object
Returns the value of attribute write_path.
Instance Method Summary collapse
- #groups ⇒ Object
-
#initialize(parser) ⇒ Writer
constructor
A new instance of Writer.
- #repo_block(repo) ⇒ Object
- #repos ⇒ Object
- #write! ⇒ Object
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
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
4 5 6 |
# File 'lib/rubolite/writer.rb', line 4 def parser @parser end |
#write_path ⇒ Object
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
#groups ⇒ Object
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.} = #{user.name}" end lines.join("\n") end |
#repos ⇒ Object
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 |