Module: IbmCloudRest
- Extended by:
- RestAPI
- Defined in:
- lib/ibm_cloud_rest/mixins/callbacks.rb,
lib/ibm_sbdtc_rest.rb,
lib/ibm_cloud_rest/core/key.rb,
lib/ibm_cloud_rest/core/image.rb,
lib/ibm_cloud_rest/core/server.rb,
lib/ibm_cloud_rest/core/address.rb,
lib/ibm_cloud_rest/core/request.rb,
lib/ibm_cloud_rest/core/storage.rb,
lib/ibm_cloud_rest/core/database.rb,
lib/ibm_cloud_rest/core/instance.rb
Overview
Extracted from ActiveSupport::Callbacks written by Yehuda Katz github.com/wycats/rails/raw/abstract_controller/activesupport/lib/active_support/new_callbacks.rb github.com/wycats/rails/raw/18b405f154868204a8f332888871041a7bad95e1/activesupport/lib/active_support/callbacks.rb
Defined Under Namespace
Modules: Callbacks Classes: Address, Database, Image, Instance, Key, Request, Server, Storage
Constant Summary collapse
- VERSION =
'0.0.0'
Class Method Summary collapse
-
.constantize(camel_cased_word) ⇒ Object
extracted from Extlib.
- .database(url) ⇒ Object
-
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created.
-
.humanize(lower_case_and_underscored_word) ⇒ Object
extracted from Extlib Capitalizes the first word and turns underscores into spaces and strips _id.
- .instances(url) ⇒ Object
-
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
- .paramify_url(url, params = {}) ⇒ Object
- .parse(url) ⇒ Object
-
.proxy(url) ⇒ Object
set proxy to use.
Methods included from RestAPI
Class Method Details
.constantize(camel_cased_word) ⇒ Object
extracted from Extlib
Constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized.
“Module”.constantize #=> Module “Class”.constantize #=> Class
63 64 65 66 67 68 69 |
# File 'lib/ibm_sbdtc_rest.rb', line 63 def constantize(camel_cased_word) unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!" end Object.module_eval("::#{$1}", __FILE__, __LINE__) end |
.database(url) ⇒ Object
146 147 148 149 150 |
# File 'lib/ibm_sbdtc_rest.rb', line 146 def database url parsed = parse url cr = IbmCloudRest.new(parsed[:host],parsed[:base_path]) cr.database(parsed[:database]) end |
.database!(url) ⇒ Object
ensure that a database exists creates it if it isn’t already there returns it after it’s been created
140 141 142 143 144 |
# File 'lib/ibm_sbdtc_rest.rb', line 140 def database! url parsed = parse url cr = IbmCloudRest.new(parsed[:host],parsed[:base_path]) cr.database!(parsed[:database]) end |
.humanize(lower_case_and_underscored_word) ⇒ Object
extracted from Extlib
Capitalizes the first word and turns underscores into spaces and strips _id. Like titleize, this is meant for creating pretty output.
79 80 81 |
# File 'lib/ibm_sbdtc_rest.rb', line 79 def humanize(lower_case_and_underscored_word) lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize end |
.instances(url) ⇒ Object
131 132 133 134 135 |
# File 'lib/ibm_sbdtc_rest.rb', line 131 def instances url parsed = parse url cr = IbmCloudRest.new(parsed[:host],parsed[:base_path]) cr.instances end |
.new(*opts) ⇒ Object
todo, make this parse the url and instantiate a Server or Database instance depending on the specificity.
85 86 87 |
# File 'lib/ibm_sbdtc_rest.rb', line 85 def new(*opts) Server.new(*opts) end |
.paramify_url(url, params = {}) ⇒ Object
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/ibm_sbdtc_rest.rb', line 152 def paramify_url url, params = {} if params && !params.empty? query = params.collect do |k,v| v = v.to_json if %w{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") url = "#{url}?#{query}" end url end |
.parse(url) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ibm_sbdtc_rest.rb', line 89 def parse url base_path_pattern=/\/cloud\/developer\/api\/rest\/\d+/ case url when /(^https:\/\/.*)(#{base_path_pattern})\/(.*)\/(.*)/ host = $1 bash_path = $2 object = $3 docid = $4 when /(^https:\/\/.*)(#{base_path_pattern})\/(.*)/ host = $1 bash_path = $2 object = $3 when /(^https:\/\/.*)/ host = $1 when /(.*)(#{base_path_pattern})\/(.*)\/(.*)/ host = $1 bash_path = $2 object = $3 docid = $4 when /(.*)(#{base_path_pattern})\/(.*)/ host = $1 bash_path = $2 object = $3 else object = url end object = nil if object && object.empty? # https://www.ibm.com/cloud/developer/api/rest/20090403/ { :host => host || "https://www.ibm.com", :base_path=> base_path || "/cloud/developer/api/rest/20090403", :object => object, :doc => docid } end |
.proxy(url) ⇒ Object
set proxy to use
127 128 129 |
# File 'lib/ibm_sbdtc_rest.rb', line 127 def proxy url HttpAbstraction.proxy = url end |