doc_my_routes 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/etc/css/base.css +2 -2
- data/etc/partial.html.erb +10 -2
- data/lib/doc_my_routes/doc/hash_helpers.rb +16 -0
- data/lib/doc_my_routes/doc/mixins/annotatable.rb +4 -1
- data/lib/doc_my_routes/doc/route.rb +16 -9
- data/lib/doc_my_routes/doc/route_documentation.rb +7 -1
- data/lib/doc_my_routes/version.rb +1 -1
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 0f789a0b78d494649c621e36704e917d37d72cf5
         | 
| 4 | 
            +
              data.tar.gz: 6374b29644c863962118ce3c76d0eecfff645a66
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 61418fb9e733596422b95254798a1885b91411be88fdae64a8369d6790d7848797cbca11bc6e72dbd2b183b2897cc85e9dd9a2eeef7d2577432b4b1396521118
         | 
| 7 | 
            +
              data.tar.gz: 05b3f7978092608493e1c189cec8d1b1974bcbd541f3d7a092e61ada04eb8db64ace13ce688c1f49fce7d3d02b8cc017a15c5c4e7d36fc7213ccfa02b097e9d8
         | 
    
        data/etc/css/base.css
    CHANGED
    
    
    
        data/etc/partial.html.erb
    CHANGED
    
    | @@ -48,12 +48,20 @@ | |
| 48 48 | 
             
                                <thead>
         | 
| 49 49 | 
             
                                  <tr>
         | 
| 50 50 | 
             
                                    <th>Parameter</th>
         | 
| 51 | 
            +
                                    <th>Required</th>
         | 
| 52 | 
            +
                                    <th>Location</th>
         | 
| 53 | 
            +
                                    <th>Type</th>
         | 
| 54 | 
            +
                                    <th>Description</th>
         | 
| 51 55 | 
             
                                  </tr>
         | 
| 52 56 | 
             
                                </thead>
         | 
| 53 57 | 
             
                                <tbody class="operation-params">
         | 
| 54 | 
            -
                                <% route[:parameters].each do | | 
| 58 | 
            +
                                <% route[:parameters].each do |param_name, param_options| %>
         | 
| 55 59 | 
             
                                  <tr>
         | 
| 56 | 
            -
                                    <td><%=  | 
| 60 | 
            +
                                    <td><%= param_name %></td>
         | 
| 61 | 
            +
                                    <td><%= param_options[:required] ? 'Yes' : 'No' %></td>
         | 
| 62 | 
            +
                                    <td><%= param_options[:in] %></td>
         | 
| 63 | 
            +
                                    <td><%= param_options[:type] %></td>
         | 
| 64 | 
            +
                                    <td><%= param_options[:description] %></td>
         | 
| 57 65 | 
             
                                  </tr>
         | 
| 58 66 | 
             
                                <% end %>
         | 
| 59 67 | 
             
                                </tbody>
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            module DocMyRoutes
         | 
| 2 | 
            +
              # Define hash helpers for deep hash merge and transforming hash into array of keys
         | 
| 3 | 
            +
              module HashHelpers
         | 
| 4 | 
            +
                def self.deep_merge(first_hash, second_hash)
         | 
| 5 | 
            +
                  merger = proc do |key, first, second|
         | 
| 6 | 
            +
                    first.is_a?(Hash) && second.is_a?(Hash) ? first.merge(second, &merger) : second
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  first_hash.merge(second_hash, &merger)
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def self.array_to_hash_keys(arr, default_value = {})
         | 
| 13 | 
            +
                  {}.tap { |hash| arr.each { |key| hash[key] = default_value } }
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -52,7 +52,6 @@ module DocMyRoutes | |
| 52 52 |  | 
| 53 53 | 
             
                def route_documentation
         | 
| 54 54 | 
             
                  @route_documentation ||= begin
         | 
| 55 | 
            -
                    DocMyRoutes.logger.debug 'Tracking new route'
         | 
| 56 55 | 
             
                    RouteDocumentation.new
         | 
| 57 56 | 
             
                  end
         | 
| 58 57 | 
             
                end
         | 
| @@ -88,6 +87,10 @@ module DocMyRoutes | |
| 88 87 | 
             
                  route_documentation.notes_ref = value
         | 
| 89 88 | 
             
                end
         | 
| 90 89 |  | 
| 90 | 
            +
                def parameter(value, options = {})
         | 
| 91 | 
            +
                  route_documentation.add_parameter(value, options)
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 91 94 | 
             
                private
         | 
| 92 95 |  | 
| 93 96 | 
             
                def track_route(resource, verb, route_pattern, conditions)
         | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 3 | 
             
            require 'forwardable'
         | 
| 4 | 
            +
            require_relative 'hash_helpers'
         | 
| 4 5 |  | 
| 5 6 | 
             
            module DocMyRoutes
         | 
| 6 7 | 
             
              # Simple object representing a route
         | 
| @@ -22,12 +23,16 @@ module DocMyRoutes | |
| 22 23 | 
             
                  @documentation = documentation
         | 
| 23 24 | 
             
                end
         | 
| 24 25 |  | 
| 26 | 
            +
                # We need to use deep merge as param_info method will return a hash for parameters
         | 
| 27 | 
            +
                # with extracted information from the route path, and documentation might also have
         | 
| 28 | 
            +
                # parameters with some more documentation and we don't want to loose extracted data
         | 
| 29 | 
            +
                # from route path
         | 
| 25 30 | 
             
                def to_hash
         | 
| 26 | 
            -
                  {
         | 
| 31 | 
            +
                  HashHelpers.deep_merge({
         | 
| 27 32 | 
             
                    http_method: verb,
         | 
| 28 33 | 
             
                    parameters: param_info,
         | 
| 29 34 | 
             
                    path: path
         | 
| 30 | 
            -
                  } | 
| 35 | 
            +
                  }, documentation.to_hash)
         | 
| 31 36 | 
             
                end
         | 
| 32 37 |  | 
| 33 38 | 
             
                def path
         | 
| @@ -60,13 +65,15 @@ module DocMyRoutes | |
| 60 65 | 
             
                #
         | 
| 61 66 | 
             
                # Try to extract parameters from the route definition otherwise
         | 
| 62 67 | 
             
                def param_info
         | 
| 63 | 
            -
                   | 
| 64 | 
            -
                     | 
| 65 | 
            -
                   | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
                   | 
| 68 | 
            +
                  path_parameters_array = route_pattern.split('/').map do |part|
         | 
| 69 | 
            +
                    part.start_with?(':') ? part[1..-1].to_sym : nil
         | 
| 70 | 
            +
                  end.compact
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  path_parameters = HashHelpers.array_to_hash_keys(path_parameters_array,
         | 
| 73 | 
            +
                                                                   { in: :path, required: true })
         | 
| 74 | 
            +
                  condition_parameters = HashHelpers.array_to_hash_keys(conditions[:parameters] || [])
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  HashHelpers.deep_merge(condition_parameters, path_parameters)
         | 
| 70 77 | 
             
                end
         | 
| 71 78 | 
             
              end
         | 
| 72 79 | 
             
            end
         | 
| @@ -3,12 +3,13 @@ module DocMyRoutes | |
| 3 3 | 
             
              class RouteDocumentation
         | 
| 4 4 | 
             
                attr_accessor :summary, :notes, :status_codes, :examples_regex, :hidden,
         | 
| 5 5 | 
             
                              :produces, :notes_ref
         | 
| 6 | 
            -
                attr_reader :examples
         | 
| 6 | 
            +
                attr_reader :examples, :parameters
         | 
| 7 7 |  | 
| 8 8 | 
             
                def initialize
         | 
| 9 9 | 
             
                  @status_codes = { 200 => DocMyRoutes::StatusCodeInfo::STATUS_CODES[200] }
         | 
| 10 10 | 
             
                  @hidden = false
         | 
| 11 11 | 
             
                  @produces = []
         | 
| 12 | 
            +
                  @parameters = {}
         | 
| 12 13 | 
             
                end
         | 
| 13 14 |  | 
| 14 15 | 
             
                # A route documentation object MUST have a summary, otherwise is not
         | 
| @@ -25,6 +26,7 @@ module DocMyRoutes | |
| 25 26 | 
             
                    examples_regex: examples_regex,
         | 
| 26 27 | 
             
                    produces: produces,
         | 
| 27 28 | 
             
                    examples: examples,
         | 
| 29 | 
            +
                    parameters: parameters,
         | 
| 28 30 | 
             
                    hidden: hidden?
         | 
| 29 31 | 
             
                  }
         | 
| 30 32 | 
             
                end
         | 
| @@ -33,6 +35,10 @@ module DocMyRoutes | |
| 33 35 | 
             
                  @produces = values.flatten.compact
         | 
| 34 36 | 
             
                end
         | 
| 35 37 |  | 
| 38 | 
            +
                def add_parameter(name, options)
         | 
| 39 | 
            +
                  @parameters[name] = options
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 36 42 | 
             
                def status_codes=(route_status_codes)
         | 
| 37 43 | 
             
                  @status_codes = Hash[route_status_codes.map do |code|
         | 
| 38 44 | 
             
                    [code, DocMyRoutes::StatusCodeInfo::STATUS_CODES[code]]
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: doc_my_routes
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.12.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Workday, Ltd.
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2017-06-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -123,6 +123,7 @@ files: | |
| 123 123 | 
             
            - lib/doc_my_routes/doc/documentation.rb
         | 
| 124 124 | 
             
            - lib/doc_my_routes/doc/errors.rb
         | 
| 125 125 | 
             
            - lib/doc_my_routes/doc/examples_handler.rb
         | 
| 126 | 
            +
            - lib/doc_my_routes/doc/hash_helpers.rb
         | 
| 126 127 | 
             
            - lib/doc_my_routes/doc/mapping.rb
         | 
| 127 128 | 
             
            - lib/doc_my_routes/doc/mixins/annotatable.rb
         | 
| 128 129 | 
             
            - lib/doc_my_routes/doc/route.rb
         |