class GrapeSlate::ExampleGenerator::Shell

Attributes

resource[R]
route[R]

Public Class Methods

new(route, resource) click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 9
def initialize(route, resource)
  @route    = route
  @resource = resource
end

Public Instance Methods

example_binding() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 18
def example_binding
  binding
end
lines() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 14
def lines
  @lines ||= [command, request, data, headers, verbose].flatten.compact
end

Private Instance Methods

command() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 32
def command
  path = route_path.split('/').reject!(&:empty?).join('/')
  "curl #{host}/#{path}"
end
data() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 47
def data
  return unless %w(POST PUT).include?(method)

  "--data '#{resource.sample_request(false)}'"
end
headers() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 53
def headers
  request_headers.map { |header| "--header '#{header.first.join(': ')}'" }
end
method() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 24
def method
  route.route_method
end
request() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 41
def request
  return unless %w(POST PUT DELETE).include?(method)

  "--request #{method}"
end
request_by_id?() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 37
def request_by_id?
  method == 'GET' && !route.list? || %w(PUT DELETE).include?(method)
end
route_path() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 28
def route_path
  route.route_path_without_format
end
verbose() click to toggle source
# File lib/grape-slate/example_generator/shell.rb, line 57
def verbose
  '--verbose'
end