phaedra 0.4.1 → 0.5.0
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 +4 -4
- data/example/api/simple.rb +2 -2
- data/example/config.ru +1 -1
- data/example/phaedra/initializers.rb +11 -0
- data/lib/phaedra.rb +1 -4
- data/lib/phaedra/base.rb +6 -2
- data/lib/phaedra/concerns/callbacks_actionable.rb +6 -6
- data/lib/phaedra/initializers.rb +69 -0
- data/lib/phaedra/rack_app.rb +3 -0
- data/lib/phaedra/rack_middleware.rb +2 -0
- data/lib/phaedra/{middleware → rack_middleware}/not_found.rb +0 -0
- data/lib/phaedra/{middleware → rack_middleware}/static.rb +0 -0
- data/lib/phaedra/version.rb +1 -1
- metadata +8 -6
- data/lib/phaedra/middleware.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed786e8ee4e64448d25817144069d17839cbae1416b6d55daec427f336183101
|
4
|
+
data.tar.gz: 8d436c4e1560ca6acda2a03c5c68a86c6d82909a78cef5c4b0052d132fa9438c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54debc72ff247af26e5414dd4684ac1fe543e4390a7ad96ed8f784ab8f8c32febb4b1b95076afb3aa62c6c72de6d9f7f6cacfaca9b9a39628fe2ba71cbe46de5
|
7
|
+
data.tar.gz: 7b1489588052128fd22902674ad41c3d28fb620ca1bdeefbf5d8131651aaa240478e6ee52d4d1f2f0758c64edb13f71edb02ceece474994eb3d18fdccf546fcf
|
data/example/api/simple.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
require_relative "../phaedra/initializers"
|
2
2
|
|
3
3
|
class PhaedraFunction < Phaedra::Base
|
4
4
|
def get(params)
|
5
5
|
response["Content-Type"] = "text/html; charset=utf-8"
|
6
|
-
"<p>This is Interesting.
|
6
|
+
"<p>This is Interesting. 😁 #{Phaedra.the_time}</p>"
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
data/example/config.ru
CHANGED
data/lib/phaedra.rb
CHANGED
data/lib/phaedra/base.rb
CHANGED
@@ -7,6 +7,10 @@ module Phaedra
|
|
7
7
|
class Base
|
8
8
|
include CallbacksActionable
|
9
9
|
|
10
|
+
before_action do
|
11
|
+
Initializers.run
|
12
|
+
end
|
13
|
+
|
10
14
|
# Used by WEBrick
|
11
15
|
def self.get_instance(server, *options)
|
12
16
|
self.new(server, *options)
|
@@ -112,7 +116,7 @@ module Phaedra
|
|
112
116
|
|
113
117
|
def set_initial_status
|
114
118
|
@res.status = 200
|
115
|
-
@res["Content-Type"] = "application/json"
|
119
|
+
@res["Content-Type"] = "application/json; charset=utf-8"
|
116
120
|
end
|
117
121
|
|
118
122
|
def call_method_action(params)
|
@@ -123,7 +127,7 @@ module Phaedra
|
|
123
127
|
def complete_response
|
124
128
|
if @res.body.is_a?(String) && !@res["Content-Type"].start_with?("text/")
|
125
129
|
@res["Content-Type"] = "text/plain; charset=utf-8"
|
126
|
-
elsif @res["Content-Type"]
|
130
|
+
elsif @res["Content-Type"].start_with? "application/json"
|
127
131
|
@res.body = @res.body.to_json
|
128
132
|
end
|
129
133
|
end
|
@@ -11,14 +11,14 @@ module Phaedra
|
|
11
11
|
end
|
12
12
|
|
13
13
|
module ClassMethods
|
14
|
-
def before_action(*args)
|
15
|
-
set_callback :action, :before, *args
|
14
|
+
def before_action(*args, &block)
|
15
|
+
set_callback :action, :before, *args, &block
|
16
16
|
end
|
17
|
-
def after_action(*args)
|
18
|
-
set_callback :action, :after, *args
|
17
|
+
def after_action(*args, &block)
|
18
|
+
set_callback :action, :after, *args, &block
|
19
19
|
end
|
20
|
-
def around_action(*args)
|
21
|
-
set_callback :action, :around, *args
|
20
|
+
def around_action(*args, &block)
|
21
|
+
set_callback :action, :around, *args, &block
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Phaedra
|
2
|
+
module Initializers
|
3
|
+
Registration = Struct.new(
|
4
|
+
:origin,
|
5
|
+
:priority,
|
6
|
+
:block,
|
7
|
+
keyword_init: true
|
8
|
+
) do
|
9
|
+
def to_s
|
10
|
+
"#{owner}:#{priority} for #{block}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
DEFAULT_PRIORITY = 20
|
15
|
+
|
16
|
+
PRIORITY_MAP = {
|
17
|
+
low: 10,
|
18
|
+
normal: 20,
|
19
|
+
high: 30,
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
# initial empty hooks
|
23
|
+
@registry = []
|
24
|
+
|
25
|
+
NotAvailable = Class.new(RuntimeError)
|
26
|
+
Uncallable = Class.new(RuntimeError)
|
27
|
+
|
28
|
+
# Ensure the priority is a Fixnum
|
29
|
+
def self.priority_value(priority)
|
30
|
+
return priority if priority.is_a?(Integer)
|
31
|
+
|
32
|
+
PRIORITY_MAP[priority] || DEFAULT_PRIORITY
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.register(origin, priority: DEFAULT_PRIORITY, &block)
|
36
|
+
raise Uncallable, "Initializers must respond to :call" unless block.respond_to? :call
|
37
|
+
|
38
|
+
@registry << Registration.new(
|
39
|
+
origin: origin,
|
40
|
+
priority: priority_value(priority),
|
41
|
+
block: block
|
42
|
+
)
|
43
|
+
|
44
|
+
block
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.remove(origin)
|
48
|
+
@registry.delete_if { |item| item.origin == origin }
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.run(force: false)
|
52
|
+
if !@initializers_ran || force
|
53
|
+
prioritized_initializers.each do |initializer|
|
54
|
+
initializer.block.call
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@initializers_ran = true
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.prioritized_initializers
|
62
|
+
# sort initializers according to priority and load order
|
63
|
+
grouped_initializers = @registry.group_by(&:priority)
|
64
|
+
grouped_initializers.keys.sort.reverse.map do |priority|
|
65
|
+
grouped_initializers[priority]
|
66
|
+
end.flatten
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/phaedra/rack_app.rb
CHANGED
File without changes
|
File without changes
|
data/lib/phaedra/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phaedra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -84,13 +84,15 @@ files:
|
|
84
84
|
- example/api/simple.rb
|
85
85
|
- example/api/the-time.rb
|
86
86
|
- example/config.ru
|
87
|
+
- example/phaedra/initializers.rb
|
87
88
|
- lib/phaedra.rb
|
88
89
|
- lib/phaedra/base.rb
|
89
90
|
- lib/phaedra/concerns/callbacks_actionable.rb
|
90
|
-
- lib/phaedra/
|
91
|
-
- lib/phaedra/middleware/not_found.rb
|
92
|
-
- lib/phaedra/middleware/static.rb
|
91
|
+
- lib/phaedra/initializers.rb
|
93
92
|
- lib/phaedra/rack_app.rb
|
93
|
+
- lib/phaedra/rack_middleware.rb
|
94
|
+
- lib/phaedra/rack_middleware/not_found.rb
|
95
|
+
- lib/phaedra/rack_middleware/static.rb
|
94
96
|
- lib/phaedra/version.rb
|
95
97
|
- phaedra.gemspec
|
96
98
|
homepage: https://github.com/whitefusionhq/phaedra
|
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
114
|
- !ruby/object:Gem::Version
|
113
115
|
version: '0'
|
114
116
|
requirements: []
|
115
|
-
rubygems_version: 3.0.
|
117
|
+
rubygems_version: 3.0.8
|
116
118
|
signing_key:
|
117
119
|
specification_version: 4
|
118
120
|
summary: Write serverless Ruby functions via a REST-like microframework compatible
|
data/lib/phaedra/middleware.rb
DELETED