Skip to content

Commit 3beab0f

Browse files
committed
Merge branch 'master' of github.com:postrank-labs/goliath
2 parents d6af453 + 4c417e5 commit 3beab0f

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

‎examples/env_use_statements.rb‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
$:<< '../lib' << 'lib'
3+
4+
require'goliath'
5+
require'yajl'
6+
7+
classEnvUseStatements < Goliath::API
8+
ifGoliath.dev?
9+
useGoliath::Rack::Render,'json'
10+
elsifGoliath.prod?
11+
useGoliath::Rack::Render,'xml'
12+
end
13+
14+
defresponse(env)
15+
[200,{},{'Test'=>'Response'}]
16+
end
17+
end

‎lib/goliath/api.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class << self
2727
#
2828
# In case of further subclassing, the very last class encountered is used.
2929
definherited(subclass)
30-
Goliath::Application.app_class=subclass.name
30+
Goliath::Application.app_class=subclass.nameifdefined?(Goliath::Application)
3131
end
3232

3333
# Retrieves the middlewares defined by this API server

‎lib/goliath/application.rb‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
require'goliath/runner'
33
require'goliath/rack'
44

5+
# Pre-load the goliath environment so it's available as we try to parse the class.
6+
# This means we can use Goliath.dev? or Goliath.prod? in the use statements.
7+
#
8+
# Note, as implmented, you have to have -e as it's own flag, you can't do -sve dev
9+
# as it won't pickup the e flag.
10+
env=ENV['RACK_ENV']
11+
env ||= begin
12+
if((i=ARGV.index('-e')) || (i=ARGV.index('--environment')))
13+
ARGV[i + 1]
14+
end
15+
end
16+
Goliath.env=envifenv
17+
518
moduleGoliath
619
# The main execution class for Goliath. This will execute in the at_exit
720
# handler to run the server.
@@ -44,14 +57,14 @@ def self.app_file
4457
c= $0 if !c || c.empty?
4558
c
4659
end
47-
60+
4861
# Returns the userland class which inherits the Goliath API
4962
#
5063
# @return [String] The app class
5164
defself.app_class
5265
@app_class
5366
end
54-
67+
5568
# Sets the userland class that should use the Goliath API
5669
#
5770
# @param app_class [String|Symbol|Constant] The new app class

‎lib/goliath/goliath.rb‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
moduleGoliath
99
module_function
1010

11-
ENVIRONMENTS=[:development,:production,:test]
11+
ENVIRONMENTS=[:development,:production,:test,:staging]
1212

1313
# Retrieves the current goliath environment
1414
#
@@ -54,4 +54,11 @@ def dev?
5454
deftest?
5555
env == :test
5656
end
57+
58+
# Determines if we are in the staging environment
59+
#
60+
# @return [Boolean] true if current environment is staging.
61+
defstaging?
62+
env == :staging
63+
end
5764
end

‎lib/goliath/test_helper.rb‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,16 @@ def put_request(request_data ={}, errback = nil, &blk)
127127
req=EM::HttpRequest.new("http://localhost:9000#{path}").put(request_data)
128128
hookup_request_callbacks(req,errback, &blk)
129129
end
130+
131+
# Make a DELETE request the currently launched API.
132+
#
133+
# @param request_data [Hash] Any data to pass to the DELETE request.
134+
# @param errback [Proc] An error handler to attach
135+
# @param blk [Proc] The callback block to execute
136+
defdelete_request(request_data={},errback=nil, &blk)
137+
path=request_data.delete(:path) || ''
138+
req=EM::HttpRequest.new("http://localhost:9000#{path}").delete(request_data)
139+
hookup_request_callbacks(req,errback, &blk)
140+
end
130141
end
131142
end

‎lib/goliath/version.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
moduleGoliath
22
# The current version of Goliath
3-
VERSION='0.9.1'
3+
VERSION='0.9.2'
44
end

0 commit comments

Comments
(0)