Sha256: c884340794ad262daedc9cfc4d48fd276b6d5372fbb47f6c874a6d2a8a4ec175
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
class GrapeSlate::ExampleGenerator::Shell attr_reader :route, :resource delegate :route_name, to: :route delegate :host, :request_headers, to: 'GrapeMarkdown::Configuration' def initialize(route, resource) @route = route @resource = resource end def lines @lines ||= [command, request, data, headers, verbose].flatten.compact end def example_binding binding end private def method route.route_method end def route_path route.route_path_without_format end def command path = route_path.split('/').reject!(&:empty?).join('/') "curl #{host}/#{path}" end def request_by_id? method == 'GET' && !route.list? || %w(PUT DELETE).include?(method) end def request return unless %w(POST PUT DELETE).include?(method) "--request #{method}" end def data return unless %w(POST PUT).include?(method) "--data '#{resource.sample_request(false)}'" end def headers request_headers.map { |header| "--header '#{header.first.join(': ')}'" } end def verbose '--verbose' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grape-slate-0.0.5 | lib/grape-slate/example_generator/shell.rb |