Class: AppMap::Swagger::Configuration
- Defined in:
- lib/appmap/swagger/configuration.rb
Constant Summary collapse
- DEFAULT_VERSION =
'1.0'
- DEFAULT_OUTPUT_DIR =
'swagger'
- DEFAULT_DESCRIPTION =
'Generate Swagger from AppMaps'
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
- #project_name ⇒ Object
-
#project_version ⇒ Object
Returns the value of attribute project_version.
- #template ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #default_project_name ⇒ Object
- #default_template ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 |
# File 'lib/appmap/swagger/configuration.rb', line 27 def initialize @project_name = nil @project_version = DEFAULT_VERSION @output_dir = DEFAULT_OUTPUT_DIR @description = DEFAULT_DESCRIPTION end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/appmap/swagger/configuration.rb', line 12 def description @description end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
12 13 14 |
# File 'lib/appmap/swagger/configuration.rb', line 12 def output_dir @output_dir end |
#project_name ⇒ Object
34 35 36 |
# File 'lib/appmap/swagger/configuration.rb', line 34 def project_name @project_name || default_project_name end |
#project_version ⇒ Object
Returns the value of attribute project_version.
12 13 14 |
# File 'lib/appmap/swagger/configuration.rb', line 12 def project_version @project_version end |
#template ⇒ Object
38 39 40 |
# File 'lib/appmap/swagger/configuration.rb', line 38 def template @template || default_template end |
Class Method Details
.load(config_data) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/appmap/swagger/configuration.rb', line 18 def load(config_data) Configuration.new.tap do |config| config_data.each do |k,v| config.send "#{k}=", v end end end |
Instance Method Details
#default_project_name ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/appmap/swagger/configuration.rb', line 58 def default_project_name # https://www.rubydoc.info/docs/rails/Module#module_parent_name-instance_method module_parent_name = ->(cls) { cls.name =~ /::[^:]+\Z/ ? $`.freeze : nil } # Lazy-evaluate this so that Rails.application will be defined. # If this code runs too early in the lifecycle, Rails.application is nil. if defined?(::Rails) [module_parent_name.(::Rails.application.class).humanize.titleize, "API"].join(" ") else "MyProject API" end end |
#default_template ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/appmap/swagger/configuration.rb', line 42 def default_template YAML.load <<~TEMPLATE openapi: 3.0.1 info: title: #{project_name} version: #{project_version} paths: components: servers: - url: http://{defaultHost} variables: defaultHost: default: localhost:3000 TEMPLATE end |