Class: RamlRubyClient::Writer

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

Constant Summary collapse

TEMP_DIR =
File.expand_path("../../../../samples", __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_dir) ⇒ Writer

Returns a new instance of Writer.



7
8
9
10
# File 'lib/raml_ruby_client/generator/writer.rb', line 7

def initialize(target_dir)
  @target_dir = target_dir
  @temp = File.join(TEMP_DIR, Time.now.to_i.to_s)
end

Instance Attribute Details

#target_dirObject (readonly)

Returns the value of attribute target_dir.



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

def target_dir
  @target_dir
end

Instance Method Details

#flushObject



24
25
26
27
28
29
# File 'lib/raml_ruby_client/generator/writer.rb', line 24

def flush
  FileUtils.mkdir_p(@target_dir)
  FileUtils.mv Dir.glob(File.join(@temp, '*')), @target_dir

  FileUtils.rm_rf(@temp)
end

#write_lib_file(path, content) ⇒ Object



20
21
22
# File 'lib/raml_ruby_client/generator/writer.rb', line 20

def write_lib_file(path, content)
  write_file(File.join(@temp, 'lib', path), content)
end

#write_root_file(name, content) ⇒ Object



12
13
14
# File 'lib/raml_ruby_client/generator/writer.rb', line 12

def write_root_file(name, content)
  write_file(File.join(@temp, name), content)
end

#write_test_file(path, content) ⇒ Object



16
17
18
# File 'lib/raml_ruby_client/generator/writer.rb', line 16

def write_test_file(path, content)
  write_file(File.join(@temp, 'test', path), content)
end