Class: Decko::Swagger
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
-
#yaml_dir ⇒ Object
Returns the value of attribute yaml_dir.
Instance Method Summary collapse
-
#gem_input_dir ⇒ Object
-
#gem_swag ⇒ Object
-
#gem_swagger_dir ⇒ Object
-
#initialize(yaml_dir = nil) ⇒ Swagger
constructor
A new instance of Swagger.
-
#merge_swag(filename, dir = nil) ⇒ Object
-
#output_file(filename = nil, dir = nil) ⇒ Object
-
#output_to_file(hash, filename = nil, dir = nil) ⇒ Object
-
#read_yml(filename, dir = nil) ⇒ Object
Constructor Details
#initialize(yaml_dir = nil) ⇒ Swagger
Returns a new instance of Swagger.
10 11 12 |
# File 'decko/lib/decko/swagger.rb', line 10 def initialize yaml_dir=nil @yaml_dir = yaml_dir end |
Instance Attribute Details
#yaml_dir ⇒ Object
Returns the value of attribute yaml_dir.
8 9 10 |
# File 'decko/lib/decko/swagger.rb', line 8 def yaml_dir @yaml_dir end |
Instance Method Details
#gem_input_dir ⇒ Object
23 24 25 |
# File 'decko/lib/decko/swagger.rb', line 23 def gem_input_dir File.join gem_swagger_dir, "input_yml" end |
#gem_swag ⇒ Object
27 28 29 |
# File 'decko/lib/decko/swagger.rb', line 27 def gem_swag read_yml :layout, gem_input_dir end |
#gem_swagger_dir ⇒ Object
19 20 21 |
# File 'decko/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 'decko/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 'decko/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 'decko/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 'decko/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 |