Class: Explicit::Documentation::Builder
- Inherits:
-
Object
- Object
- Explicit::Documentation::Builder
- Defined in:
- lib/explicit/documentation/builder.rb
Instance Attribute Summary collapse
-
#rails_engine ⇒ Object
readonly
Returns the value of attribute rails_engine.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#swagger ⇒ Object
readonly
Returns the value of attribute swagger.
-
#webpage ⇒ Object
readonly
Returns the value of attribute webpage.
Instance Method Summary collapse
- #add(*requests, **opts) ⇒ Object
- #company_logo_url(url) ⇒ Object
- #favicon_url(url) ⇒ Object
- #get_company_logo_url ⇒ Object
- #get_favicon_url ⇒ Object
- #get_page_title ⇒ Object
- #get_version ⇒ Object
-
#initialize(rails_engine) ⇒ Builder
constructor
A new instance of Builder.
- #merge_request_examples_from_file! ⇒ Object
- #page_title(text) ⇒ Object
- #requests ⇒ Object
- #section(name, &block) ⇒ Object
- #version(version) ⇒ Object
Constructor Details
#initialize(rails_engine) ⇒ Builder
Returns a new instance of Builder.
7 8 9 10 11 12 13 14 |
# File 'lib/explicit/documentation/builder.rb', line 7 def initialize(rails_engine) @rails_engine = rails_engine @sections = [] @current_section = nil @version = "1.0" @swagger = Output::Swagger.new(self) @webpage = Output::Webpage.new(self) end |
Instance Attribute Details
#rails_engine ⇒ Object (readonly)
Returns the value of attribute rails_engine.
5 6 7 |
# File 'lib/explicit/documentation/builder.rb', line 5 def rails_engine @rails_engine end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
5 6 7 |
# File 'lib/explicit/documentation/builder.rb', line 5 def sections @sections end |
#swagger ⇒ Object (readonly)
Returns the value of attribute swagger.
5 6 7 |
# File 'lib/explicit/documentation/builder.rb', line 5 def swagger @swagger end |
#webpage ⇒ Object (readonly)
Returns the value of attribute webpage.
5 6 7 |
# File 'lib/explicit/documentation/builder.rb', line 5 def webpage @webpage end |
Instance Method Details
#add(*requests, **opts) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/explicit/documentation/builder.rb', line 42 def add(*requests, **opts) raise ArgumentError(<<-MD) if @current_section.nil? You must define a section before adding a page. For example: section "Customers" do add CustomersController::CreateRequest end MD if requests.one? @current_section.pages << Page::Request.new(request: requests.first) elsif opts[:partial] @current_section.pages << Page::Partial.new(title: opts[:title], partial: opts[:partial]) else raise ArgumentError("expected request or a partial") end end |
#company_logo_url(url) ⇒ Object
19 |
# File 'lib/explicit/documentation/builder.rb', line 19 def company_logo_url(url) = (@company_logo_url = url) |
#favicon_url(url) ⇒ Object
22 |
# File 'lib/explicit/documentation/builder.rb', line 22 def favicon_url(url) = (@favicon_url = url) |
#get_company_logo_url ⇒ Object
20 |
# File 'lib/explicit/documentation/builder.rb', line 20 def get_company_logo_url = @company_logo_url |
#get_favicon_url ⇒ Object
23 |
# File 'lib/explicit/documentation/builder.rb', line 23 def get_favicon_url = @favicon_url |
#get_page_title ⇒ Object
17 |
# File 'lib/explicit/documentation/builder.rb', line 17 def get_page_title = @page_title |
#get_version ⇒ Object
26 |
# File 'lib/explicit/documentation/builder.rb', line 26 def get_version = @version |
#merge_request_examples_from_file! ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/explicit/documentation/builder.rb', line 60 def merge_request_examples_from_file! return if !Explicit.configuration.request_examples_file_path return if !::File.exist?(Explicit.configuration.request_examples_file_path) encoded = ::File.read(Explicit.configuration.request_examples_file_path) examples = ::JSON.parse(encoded) requests.each do |request| examples[request.gid]&.each do |example| request.example( params: example["params"].with_indifferent_access, headers: example["headers"], response: { status: example.dig("response", "status"), data: example.dig("response", "data").with_indifferent_access } ) end end rescue JSON::ParserError ::Rails.logger.error("[Explicit] Could not parse JSON in request examples file at #{Explicit.configuration.request_examples_file_path}") end |
#page_title(text) ⇒ Object
16 |
# File 'lib/explicit/documentation/builder.rb', line 16 def page_title(text) = (@page_title = text) |
#requests ⇒ Object
38 39 40 |
# File 'lib/explicit/documentation/builder.rb', line 38 def requests @sections.flat_map(&:pages).filter(&:request?).map(&:request) end |
#section(name, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/explicit/documentation/builder.rb', line 28 def section(name, &block) @current_section = Section.new(name:, pages: []) block.call @sections << @current_section @current_section = nil end |
#version(version) ⇒ Object
25 |
# File 'lib/explicit/documentation/builder.rb', line 25 def version(version) = (@version = version) |