class Brainstem::ApiDocs::Sinks::ControllerPresenterMultifileSink

Attributes

atlas[RW]
format[RW]
write_method[W]
write_path[W]

Public Instance Methods

<<(atlas) click to toggle source
# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 13
def <<(atlas)
  self.atlas = atlas

  write_controller_files
  write_presenter_files
end
valid_options() click to toggle source
# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 20
def valid_options
  super | [ :write_method, :format, :write_path ]
end

Private Instance Methods

assert_directory_exists!(path) click to toggle source

Asserts that a directory exists, creating it if it does not.

# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 64
def assert_directory_exists!(path)
  dir = File.dirname(path)
  FileUtils.mkdir_p(dir) unless File.directory?(dir)
end
write_buffer_to_file(buffer, filename) click to toggle source

Writes a given bufer to a filename within the base path.

# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 55
def write_buffer_to_file(buffer, filename)
  abs_path = File.join(write_path, filename)
  assert_directory_exists!(abs_path)
  write_method.call(abs_path, buffer)
end
write_controller_files() click to toggle source

Dumps each formatted controller to a file.

# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 37
def write_controller_files
  controllers.each_formatted_with_filename(
    format,
    include_actions: true,
    &method(:write_buffer_to_file)
  )
end
write_method() click to toggle source

Defines how we write out the files.

# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 72
def write_method
  @write_method ||= Proc.new do |name, buff|
    File.write(name, buff, mode: 'w')
  end
end
write_path() click to toggle source
# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 78
def write_path
  @write_path ||= ::Brainstem::ApiDocs.write_path
end
write_presenter_files() click to toggle source

Dumps each formatted presenter to a file.

# File lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb, line 48
def write_presenter_files
  presenters.each_formatted_with_filename(format, &method(:write_buffer_to_file))
end