class Kumonos::Output

Output manipulation.

Public Class Methods

new(dir, type, name) click to toggle source
# File lib/kumonos/output.rb, line 8
def initialize(dir, type, name)
  @dir = Pathname.new(dir)
  @type = type
  @name = name
end

Public Instance Methods

write(json) click to toggle source
# File lib/kumonos/output.rb, line 14
def write(json)
  target =
    case @type
    when :clusters
      @dir.join('v1', 'clusters', @name, @name)
    when :routes
      @dir.join('v1', 'routes', Kumonos::DEFAULT_ROUTE_NAME, @name, @name)
    else
      raise %(Unknown type "#{@type}" given)
    end
  target.parent.mkpath unless target.parent.exist?
  target.write(json)
  target
end