Class: Decko::Swagger

Inherits:
Object
  • Object
show all
Defined in:
lib/decko/swagger.rb

Overview

hacky first go at swagger generation.

In decko, it really just converts yaml to ruby and back again.

But it’s useful for generating decko swagger docs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_dir = nil) ⇒ Swagger

Returns a new instance of Swagger.



10
11
12
# File 'lib/decko/swagger.rb', line 10

def initialize yaml_dir=nil
  @yaml_dir = yaml_dir
end

Instance Attribute Details

#yaml_dirObject

Returns the value of attribute yaml_dir.



8
9
10
# File 'lib/decko/swagger.rb', line 8

def yaml_dir
  @yaml_dir
end

Instance Method Details

#gem_input_dirObject



23
24
25
# File 'lib/decko/swagger.rb', line 23

def gem_input_dir
  File.join gem_swagger_dir, "input_yml"
end

#gem_swagObject



27
28
29
# File 'lib/decko/swagger.rb', line 27

def gem_swag
  read_yml :layout, gem_input_dir
end

#gem_swagger_dirObject



19
20
21
# File 'lib/decko/swagger.rb', line 19

def gem_swagger_dir
  File.join Decko.gem_root, "lib/decko/swagger"
end

#merge_swag(filename, dir = nil) ⇒ Object



31
32
33
34
# File 'lib/decko/swagger.rb', line 31

def merge_swag filename, dir=nil
  yaml = read_yml filename, dir
  gem_swag.deep_merge yaml
end

#output_file(filename = nil, dir = nil) ⇒ Object



36
37
38
39
40
# File 'lib/decko/swagger.rb', line 36

def output_file filename=nil, dir=nil
  filename ||= "output.yml"
  dir ||= yaml_dir || gem_input_dir
  File.join dir, filename
end

#output_to_file(hash, filename = nil, dir = nil) ⇒ Object



42
43
44
# File 'lib/decko/swagger.rb', line 42

def output_to_file hash, filename=nil, dir=nil
  File.write output_file(filename, dir), hash.to_yaml
end

#read_yml(filename, dir = nil) ⇒ Object



14
15
16
17
# File 'lib/decko/swagger.rb', line 14

def read_yml filename, dir=nil
  dir ||= yaml_dir || gem_input_dir
  YAML.load_file File.join(dir, "#{filename}.yml")
end