objectsframework 1.2 → 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8473759ee5a1dcf0869209554775c3bbf357c19b
|
4
|
+
data.tar.gz: 5f1bf46f201910b77a8d1533eaf9b8923cc3e2ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31331c5f6f94730c621663814a2293f6ac16b7eae739563a2993e600657e12282fda9c3f0e8b8606a88c5bdfe620d820b3a666fced5302a58f79612a8f8a9632
|
7
|
+
data.tar.gz: 082b5bbe45575af69f5395c95b7ce785b98fc39715c8b807b345f6ddfd77e5002793f46618c31c483260b726bba21dc1dac8c6dcad24199193638245091a466c
|
@@ -3,8 +3,19 @@ module ObjectsFramework
|
|
3
3
|
def self.fire(filter, klass)
|
4
4
|
hooks_to_execute = klass.class.get_hooks.select { |hook| hook[:filter] == filter }
|
5
5
|
hooks_to_execute.each do |hook|
|
6
|
-
klass.send(hook[:method].to_sym)
|
6
|
+
result = klass.send(hook[:method].to_sym)
|
7
|
+
return result unless result == 0
|
7
8
|
end
|
9
|
+
return 0
|
8
10
|
end
|
11
|
+
|
12
|
+
def self.hook_exists?(filter,klass)
|
13
|
+
!(klass.class.get_hooks.select{|hook| hook[:filter] == filter}).empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.continue
|
17
|
+
return 0
|
18
|
+
end
|
19
|
+
|
9
20
|
end
|
10
21
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ObjectsFramework
|
2
2
|
class Object
|
3
|
-
def set_instance_variables(request,response)
|
4
|
-
@request,@response = request,response
|
3
|
+
def set_instance_variables(request,response,env)
|
4
|
+
@request,@response,@env = request,response,env
|
5
5
|
return self;
|
6
6
|
end
|
7
7
|
|
@@ -13,6 +13,10 @@ module ObjectsFramework
|
|
13
13
|
@response
|
14
14
|
end
|
15
15
|
|
16
|
+
def continue
|
17
|
+
return 0
|
18
|
+
end
|
19
|
+
|
16
20
|
# Object hooks:
|
17
21
|
# Usage: add_hook :filter => "afilter", :method => "yourmethod"
|
18
22
|
# Available hooks/filters (some are not implement yet, but planned):
|
@@ -20,6 +24,9 @@ module ObjectsFramework
|
|
20
24
|
# * request.finished: fired when the request is finished and the response is about to get served [planned]
|
21
25
|
# * server.ready: fired when the server is ready accepting connections [planned]
|
22
26
|
# * server.error: fired when an internal error happens (for example method not found) [planned]
|
27
|
+
# * request.capture: capture the request before anything happens, like a real pirate! (fired after your object is created)
|
28
|
+
# if the result of your hook returns true, the request must be finished by your hook
|
29
|
+
# this can block the request
|
23
30
|
# All hooks are blocking, so they could eventually block the request [Future testing required]
|
24
31
|
@@hooks = []
|
25
32
|
|
@@ -11,15 +11,26 @@ module ObjectsFramework
|
|
11
11
|
parts = path.split("/")
|
12
12
|
if(path == "/" && !context.config[:root].nil?)
|
13
13
|
klass = Object.const_get(context.config[:root]).new
|
14
|
+
klass.set_instance_variables(request,response,context.env)
|
15
|
+
|
16
|
+
captured_result = captured?(klass)
|
17
|
+
if(captured_result != 0)
|
18
|
+
return captured_result
|
19
|
+
end
|
14
20
|
|
15
21
|
Hooks.fire("object.before_execute", klass)
|
16
22
|
|
17
|
-
klass.
|
18
|
-
return
|
23
|
+
klass.send(request.request_method.downcase!+"_"+context.config[:index_method])
|
24
|
+
return true
|
19
25
|
end
|
20
26
|
|
21
27
|
begin
|
22
|
-
klass = Object.const_get(parts[1].capitalize).new.set_instance_variables(request,response)
|
28
|
+
klass = Object.const_get(parts[1].capitalize).new.set_instance_variables(request,response,context.env)
|
29
|
+
|
30
|
+
captured_result = captured?(klass)
|
31
|
+
if(captured_result != 0)
|
32
|
+
return captured_result
|
33
|
+
end
|
23
34
|
|
24
35
|
Hooks.fire("object.before_execute", klass)
|
25
36
|
|
@@ -34,21 +45,38 @@ module ObjectsFramework
|
|
34
45
|
end
|
35
46
|
rescue Exception => e
|
36
47
|
begin
|
37
|
-
obj = Object.const_get(context.config[:root]).new.set_instance_variables(request,response)
|
48
|
+
obj = Object.const_get(context.config[:root]).new.set_instance_variables(request,response,context.env)
|
49
|
+
|
50
|
+
captured_result = captured?(obj)
|
51
|
+
if(captured_result != 0)
|
52
|
+
return captured_result
|
53
|
+
end
|
54
|
+
|
38
55
|
Hooks.fire("object.before_execute", obj)
|
39
56
|
obj.send(request.request_method.downcase!+"_"+parts[1])
|
40
|
-
return
|
57
|
+
return true
|
41
58
|
rescue
|
42
59
|
|
43
60
|
end
|
44
61
|
response.status = 404
|
45
62
|
notfound_response(response,e)
|
46
63
|
end
|
47
|
-
|
64
|
+
return true
|
48
65
|
end
|
49
66
|
|
50
67
|
def self.notfound_response(response,e)
|
51
68
|
response.write "<h1>404 Not Found</h1><hr/><i>Ruby Rack Server powered by ObjectsFramework <br/><pre>#{e.to_s}</pre></i>"
|
52
69
|
end
|
70
|
+
|
71
|
+
def self.captured?(klass)
|
72
|
+
if(Hooks.hook_exists?("request.capture",klass))
|
73
|
+
result = Hooks.fire("request.capture",klass)
|
74
|
+
if(result != 0)
|
75
|
+
return result
|
76
|
+
end
|
77
|
+
return 0
|
78
|
+
end
|
79
|
+
return 0
|
80
|
+
end
|
53
81
|
end
|
54
82
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module ObjectsFramework
|
2
2
|
class Server
|
3
|
-
attr_accessor :config
|
3
|
+
attr_accessor :config, :env
|
4
4
|
|
5
5
|
def initialize(config = {})
|
6
6
|
@config = {:index_method => "index"}.merge(config)
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(env)
|
10
|
+
@env = env
|
10
11
|
request = Rack::Request.new(env)
|
11
12
|
response = Rack::Response.new(env)
|
12
13
|
# Solves some weird bug where ENV is added to the response body
|
@@ -14,8 +15,12 @@ module ObjectsFramework
|
|
14
15
|
response.length = 0
|
15
16
|
# Set text/html as Content-type by default
|
16
17
|
response.header["Content-type"] = "text/html"
|
17
|
-
ObjectsFramework::ObjectHandler.run_methods(request,response,self)
|
18
|
-
|
18
|
+
handler = ObjectsFramework::ObjectHandler.run_methods(request,response,self)
|
19
|
+
if(handler === true)
|
20
|
+
response.finish
|
21
|
+
else
|
22
|
+
return handler
|
23
|
+
end
|
19
24
|
end
|
20
25
|
end
|
21
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: objectsframework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bram Vandenbogaerde
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- lib/objectsframework.rb
|
49
|
+
- lib/objectsframework/hook_helper.rb
|
49
50
|
- lib/objectsframework/hooks.rb
|
50
51
|
- lib/objectsframework/object.rb
|
51
52
|
- lib/objectsframework/object_handler.rb
|