Class: Xdrgen::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/xdrgen/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_paths, output_dir) ⇒ Output

Returns a new instance of Output.



9
10
11
12
13
# File 'lib/xdrgen/output.rb', line 9

def initialize(source_paths, output_dir)
  @source_paths = source_paths
  @output_dir = output_dir
  @files      = {}
end

Instance Attribute Details

#output_dirObject (readonly)

Returns the value of attribute output_dir.



7
8
9
# File 'lib/xdrgen/output.rb', line 7

def output_dir
  @output_dir
end

#source_pathsObject (readonly)

Returns the value of attribute source_paths.



6
7
8
# File 'lib/xdrgen/output.rb', line 6

def source_paths
  @source_paths
end

Instance Method Details

#closeObject



32
33
34
# File 'lib/xdrgen/output.rb', line 32

def close
  @files.values.each(&:close)
end

#open(child_path) {|result| ... } ⇒ Object

Yields:

  • (result)


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xdrgen/output.rb', line 15

def open(child_path)
  if @files.has_key?(child_path)
    raise Xdrgen::DuplicateFileError, "Cannot open #{child_path} twice"
  end 

  path = File.join @output_dir, child_path
  result = @files[child_path] = OutputFile.new(path)

  yield result if block_given?

  result
end

#write(child_path, content) ⇒ Object



28
29
30
# File 'lib/xdrgen/output.rb', line 28

def write(child_path, content)
  open(child_path){|c| c.puts content}
end