Module: Swagger::Shell::Interface
- Defined in:
- lib/swagger/shell/interface.rb
Instance Method Summary collapse
- #api ⇒ Object
-
#apis(option = "") ⇒ 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 = "") ⇒ Object
output API list
option # TODO: implement p: output parameter name s: output summary
no option output summary.
e.g.: swagger-shell(main)> apis :p
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/swagger/shell/interface.rb', line 55 def apis(option = "") 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| output = "#{api}#{" " * (max_key_size - api.size)}" output += " # #{(operation["parameters"] || []).map {|p| p["name"][8..-2] }.join(" ")}" if with_parameter output += " # #{operation["summary"]}" if with_summary puts output 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 |
#user ⇒ Object
26 27 28 |
# File 'lib/swagger/shell/interface.rb', line 26 def user Swagger::Shell.user end |