class Swagger::Template::Tasks::Writer
Public Class Methods
new(options = {})
click to toggle source
# File lib/swagger/template/tasks/writer.rb, line 8 def initialize(options = {}) @endpoints = options[:endpoints] @options = options end
Public Instance Methods
render(filename, endpoint)
click to toggle source
# File lib/swagger/template/tasks/writer.rb, line 19 def render(filename, endpoint) @template_filename = "#{@options[:templates_path]}" \ "/#{@options[:language]}/#{filename}.erb" @template = File.read(@template_filename) rendered = ERB.new(@template, nil, '-').result(binding).tap{|ob| puts ob } directory = "#{@options[:output_path]}/#{endpoint.dirname}" filename = "#{@options[:output_path]}/#{endpoint.filename}.rb" FileUtils.mkdir_p(directory) unless File.directory?(directory) File.open(filename, 'w') { |file| file.write(rendered) } end
write()
click to toggle source
# File lib/swagger/template/tasks/writer.rb, line 13 def write @endpoints.each do |endpoint| render('endpoint', endpoint) end end