Class: Flight::Router::Drawer

Inherits:
Object
  • Object
show all
Defined in:
lib/flight/router/drawer.rb

Instance Method Summary collapse

Constructor Details

#initialize(project:, output_dir:, input_dir:, env:) ⇒ Drawer

Returns a new instance of Drawer.



5
6
7
8
9
10
# File 'lib/flight/router/drawer.rb', line 5

def initialize(project:,output_dir:,input_dir:,env:)
  @project = project
  @output_dir = output_dir
  @map = Map.new(env: env.to_sym, input_dir: File.join(input_dir,project))
  @app = App.new(@map)
end

Instance Method Details

#app(&block) ⇒ Object



15
16
17
# File 'lib/flight/router/drawer.rb', line 15

def app(&block)
  @app.instance_exec(&block)
end

#build(&block) ⇒ Object



24
25
26
27
28
29
# File 'lib/flight/router/drawer.rb', line 24

def build(&block)
  path = File.join("/", @project)
  container = Container.new([path], app: @app.config, map: @map.map, output_dir: @output_dir)
  container.instance_exec(&block)
  container.config
end

#draw(&block) ⇒ Object



19
20
21
22
23
# File 'lib/flight/router/drawer.rb', line 19

def draw(&block)
  dir = File.join(@output_dir,@project)
  FileUtils.mkdir_p(dir)
  File.write File.join(dir,"routes.json"), JSON.generate(build(&block))
end

#map(&block) ⇒ Object



12
13
14
# File 'lib/flight/router/drawer.rb', line 12

def map(&block)
  @map.instance_exec(&block)
end