Sha256: f5003ea45422f020fc150f49bf5acef0fbcae5c34b1635def5c7e31e28b04b1c

Contents?: true

Size: 1.18 KB

Versions: 6

Compression:

Stored size: 1.18 KB

Contents

module Dox
  module Printers
    class ActionPrinter < BasePrinter
      def print(action)
        self.action = action
        @output.puts action_title
        @output.puts action_uri_params if action.uri_params.present?

        action.examples.each do |example|
          example_printer.print(example)
        end
      end

      private

      attr_accessor :action

      def action_title
        <<-HEREDOC

### #{action.name} [#{action.verb.upcase} #{action.path}]
#{print_desc(action.desc)}
        HEREDOC
      end

      def action_uri_params
        <<-HEREDOC
+ Parameters
#{formatted_params(action.uri_params)}
        HEREDOC
      end

      def example_printer
        @example_printer ||= ExamplePrinter.new(@output)
      end

      def formatted_params(uri_params)
        uri_params.map do |param, details|
          desc = "    + #{CGI.escape(param.to_s)}: `#{CGI.escape(details[:value].to_s)}` (#{details[:type]}, #{details[:required]})"
          desc += " - #{details[:description]}" if details[:description].present?
          desc += "\n        + Default: #{details[:default]}" if details[:default].present?
          desc
        end.flatten.join("\n")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dox-1.3.0 lib/dox/printers/action_printer.rb
dox-1.2.0 lib/dox/printers/action_printer.rb
dox-1.1.0 lib/dox/printers/action_printer.rb
dox-1.0.2 lib/dox/printers/action_printer.rb
dox-1.0.1 lib/dox/printers/action_printer.rb
dox-1.0.0 lib/dox/printers/action_printer.rb