Class: Thebes::ConfigWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/thebes/config_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(template_path = nil, template_file = nil) ⇒ ConfigWriter

Returns a new instance of ConfigWriter.



7
8
9
10
# File 'lib/thebes/config_writer.rb', line 7

def initialize template_path=nil, template_file=nil
  @template_path = template_path || File.join(File.dirname(__FILE__), '..', '..', 'templates')
  @template_file = template_file || 'sphinx.conf'
end

Instance Method Details

#build(outfile = nil, locals = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/thebes/config_writer.rb', line 16

def build(outfile=nil, locals={})
  outfile ||= default_config_file
  view = ActionView::Base.new(
    @template_path,
    locals
  )
  File.open(outfile, 'w') do |file|
    file.write view.render(:file => @template_file)
  end
end

#default_config_fileObject



12
13
14
# File 'lib/thebes/config_writer.rb', line 12

def default_config_file
  "./#{@@config_template}"
end