Class: Temill::Emitters::DirectoryEmitter

Inherits:
Base
  • Object
show all
Defined in:
lib/temill/emitter.rb

Instance Method Summary collapse

Methods inherited from Base

#annotation, #call, #emit_for_source_file

Constructor Details

#initialize(dir_path, options) ⇒ DirectoryEmitter

Returns a new instance of DirectoryEmitter.



74
75
76
77
# File 'lib/temill/emitter.rb', line 74

def initialize(dir_path, options)
  @dir_path = Pathname.new(dir_path)
  super(options)
end

Instance Method Details

#execute(source_files) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/temill/emitter.rb', line 79

def execute(source_files)
  FileUtils.makedirs(@dir_path)
  written = []
  source_files.each{| sf |
    fname = output_fname(sf.path, written)
    File.open(fname, 'w'){| f |
      emit_for_source_file(sf, f)
      written << fname
    }
  }
  nil
end

#output_fname(base_fname, written) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/temill/emitter.rb', line 92

def output_fname(base_fname, written)
  fname_base = (@dir_path + File.basename(base_fname)).to_s
  current_fname = fname_base
  suffix_n = 1
  while written.include?(current_fname)
    current_fname = fname_base + ".#{suffix_n}"
    suffix_n += 1
  end
  current_fname
end