Module: Rackget
- Defined in:
- lib/rackget.rb,
lib/rackget/cli.rb,
lib/rackget/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .get(app, path, query_string: nil) ⇒ Object
- .load_app(rackup_file) ⇒ Object
- .request(app, path, method: "GET", query_string: nil, input: nil, headers: {}) ⇒ Object
Class Method Details
.get(app, path, query_string: nil) ⇒ Object
37 38 39 |
# File 'lib/rackget.rb', line 37 def self.get(app, path, query_string: nil) request(app, path, method: "GET", query_string: query_string) end |
.load_app(rackup_file) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/rackget.rb', line 13 def self.load_app(rackup_file) raise Error, "File not found: #{rackup_file}" unless File.exist?(rackup_file) result = Rack::Builder.parse_file(rackup_file) result.is_a?(Array) ? result.first : result end |
.request(app, path, method: "GET", query_string: nil, input: nil, headers: {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rackget.rb', line 20 def self.request(app, path, method: "GET", query_string: nil, input: nil, headers: {}) url = path.dup url = "#{url}?#{query_string}" if query_string && !query_string.empty? opts = { method: method } opts[:input] = input if input headers.each do |name, value| key = name.upcase.tr("-", "_") key = "HTTP_#{key}" unless key == "CONTENT_TYPE" || key == "CONTENT_LENGTH" opts[key] = value end env = Rack::MockRequest.env_for(url, opts) app.call(env) end |