Class: Kumonos::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/kumonos/output.rb

Overview

Output manipulation.

Instance Method Summary collapse

Constructor Details

#initialize(dir, type, name) ⇒ Output

Returns a new instance of Output.



8
9
10
11
12
# File 'lib/kumonos/output.rb', line 8

def initialize(dir, type, name)
  @dir = Pathname.new(dir)
  @type = type
  @name = name
end

Instance Method Details

#write(json) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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