Module: Swagger::Shell

Defined in:
lib/swagger/shell.rb,
lib/swagger/shell/user.rb,
lib/swagger/shell/version.rb,
lib/swagger/shell/interface.rb,
lib/swagger/shell/api_struct.rb,
lib/swagger/shell/doc_loader.rb

Defined Under Namespace

Modules: ApiDelete, ApiGet, ApiPost, ApiPut, Interface Classes: ApiStruct, DocLoader, User

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.apiObject



44
45
46
# File 'lib/swagger/shell.rb', line 44

def api
  @aip ||= DocLoader.new.load(config_env.docs_url)
end

.config_apiObject



26
27
28
29
30
# File 'lib/swagger/shell.rb', line 26

def config_api
  @config_api ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["api"]).tap do |_config|  # TODO: pass outside
    # noting to do
  end
end

.config_envObject



19
20
21
22
23
24
# File 'lib/swagger/shell.rb', line 19

def config_env
  @config_env ||= hash_to_struct(YAML.load_file("config/env.yml")[env.to_s]).tap do |config|  # TODO: pass outside
    raise "not exist env: #{env}" if config.nil?
    config.docs_url = File.join(config.api_url, config.docs_url) unless config.docs_url.start_with? "http"
  end
end

.config_pryObject



32
33
34
35
36
37
38
# File 'lib/swagger/shell.rb', line 32

def config_pry
  @config_local ||= hash_to_struct(YAML.load_file("config/swagger-shell.yml")["pry"]).tap do |config| # TODO: pass outside
    config.home = config.home.gsub(/^~/, Dir.home) if config.home.start_with?("~/")
    config.history_path = File.join(config.home, config.history_file)
    config.users_path = File.join(config.home, config.users_file)
  end
end

.envObject



15
16
17
# File 'lib/swagger/shell.rb', line 15

def env
  @env
end

.env=(env) ⇒ Object



11
12
13
# File 'lib/swagger/shell.rb', line 11

def env=(env)
  @env = env
end

.hash_to_struct(hash) ⇒ Object



65
66
67
# File 'lib/swagger/shell.rb', line 65

def hash_to_struct(hash)
  JSON.parse hash.to_json, object_class: OpenStruct
end

.register_interface(interface_module) ⇒ Object



52
53
54
# File 'lib/swagger/shell.rb', line 52

def register_interface(interface_module)
  registered_interfaces << interface_module
end

.registered_interfacesObject



48
49
50
# File 'lib/swagger/shell.rb', line 48

def registered_interfaces
  @registered_interfaces ||= []
end

.start(main, env = nil) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/swagger/shell.rb', line 56

def start(main, env = nil)
  self.env = env || :default
  main.extend Swagger::Shell::Interface
  registered_interfaces.each do |interface|
    main.extend interface
  end
  main.start_shell
end

.userObject



40
41
42
# File 'lib/swagger/shell.rb', line 40

def user
  @user ||= User.new
end