Module: Swagger::Shell::Interface
- Defined in:
- lib/swagger/shell/interface.rb
Instance Method Summary collapse
- #api ⇒ Object
-
#apis(option = :ps) ⇒ Object
output API list.
- #bootstrap ⇒ Object
- #start_shell ⇒ Object
- #user ⇒ Object
Instance Method Details
#api ⇒ Object
22 23 24 |
# File 'lib/swagger/shell/interface.rb', line 22 def api Swagger::Shell.api end |
#apis(option = :ps) ⇒ Object
output API list
option p: output parameter name s: output summary
no option output summary.
e.g.: swagger-shell(main)> apis :ps
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/swagger/shell/interface.rb', line 55 def apis(option = :ps) option = option.to_s with_parameter = option.include?("p") with_summary = option.include?("s") || option.size.zero? api_list = api.api_list max_key_size = api_list.keys.map(&:size).max api_list.sort.each do |api, operation| comments = [] comments << operation.summary if with_summary comments << "(#{(operation.parameters || []).map {|p| p["name"][8..-2] }.map {|n| "#{n}:" }.join(", ")})" if with_parameter puts "#{api}#{" " * (max_key_size - api.size)} # #{comments.join(" ")}" end nil end |
#bootstrap ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/swagger/shell/interface.rb', line 30 def bootstrap user.load_sample begin if user.info.nil? user.create puts "create user_id: #{user.id}" else user.login puts "load user_id: #{user.id}" end rescue puts "failed load user_id: #{user.id}" end end |
#start_shell ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/swagger/shell/interface.rb', line 10 def start_shell Pry.config.prompt_name = Swagger::Shell.config_pry.prompt_name || "swagger-shell" FileUtils.mkdir_p(Swagger::Shell.config_pry.home) Pry.config.history.file = Swagger::Shell.config_pry.history_path || "~/.swagger-shell/history" bootstrap Pry.history.load Pry.start end |