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.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.config_apiObject

Returns the value of attribute config_api.



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

def config_api
  @config_api
end

.config_pryObject

Returns the value of attribute config_pry.



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

def config_pry
  @config_pry
end

.envObject

Returns the value of attribute env.



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

def env
  @env
end

Class Method Details

.apiObject



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

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

.config_envObject



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

def config_env
  @config_env ||= @config_env_store[env].tap do |config|
    config.docs_url = File.join(config.api_url, config.docs_url) unless config.docs_url.start_with? "http"
  end
end

.config_env=(config) ⇒ Object



17
18
19
# File 'lib/swagger/shell.rb', line 17

def config_env=(config)
  @config_env_store = hash_to_struct(config)
end

.hash_to_struct(hash) ⇒ Object



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

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

.register_interface(interface_module) ⇒ Object



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

def register_interface(interface_module)
  registered_interfaces << interface_module
end

.registered_interfacesObject



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

def registered_interfaces
  @registered_interfaces ||= []
end

.start(main, env = nil) ⇒ Object



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

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



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

def user
  @user ||= User.new
end