class NvimConf::Writers::Code::Orchestrator

Constants

NON_WRITABLE_MANAGER
WRITER_CONFIGURATION

Public Class Methods

new(managers, io, configuration = nil) click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 23
def initialize(managers, io, configuration = nil)
  @managers = managers
  @io = io
  @configuration = configuration || default_configuration
end

Public Instance Methods

aggregate_writes() click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 29
def aggregate_writes
  @managers.select { |manager| manager.class != NON_WRITABLE_MANAGER }.each_with_index do |manager, index|
    @io.write(
      NvimConf::Commenter.comment_block(
        @configuration,
        manager_section_name(manager),
        spacer: index.positive?
      )
    )

    if index.positive? || @configuration[:commented]
      @io.write(
        separator
      )
    end

    aggregate_writes_for_manager(manager)
  end
end

Private Instance Methods

aggregate_writes_for_manager(manager) click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 65
def aggregate_writes_for_manager(manager)
  WRITER_CONFIGURATION[manager.class]&.new(
    manager, @io, **@configuration.slice(:format, :commented)
  )&.write
end
default_configuration() click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 71
def default_configuration
  {
    format: :lua,
    commented: false
  }
end
manager_section_name(manager) click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 51
def manager_section_name(manager)
  return manager.class.section_name unless manager.respond_to?(:title)
  return manager.class.section_name if manager.title.nil?

  [
    manager.class.section_name,
    manager.title
  ].join(" - ")
end
separator() click to toggle source
# File lib/nvim_conf/writers/code/orchestrator.rb, line 61
def separator
  "\n\n"
end