rackr 0.0.61 → 0.0.63
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/lib/rackr/action.rb +10 -0
- data/lib/rackr.rb +42 -22
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e5510a8382fb76e2ecd76fb38f024753d2bece6771aeac87f4fa8f000e14bb7
|
|
4
|
+
data.tar.gz: 48e121278f8b5dc8eac591883e9e40d6ecc43f6116dd4ee6abe3130da8956186
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cbcfc075222a1f7b7b39a2106f6bff6192616f76879bc05515b53db3654ca9733b9003cc8c6fa637b57ac3e0daff4b00489589176ece200820249fae4d8fbe4f
|
|
7
|
+
data.tar.gz: 4f3314ff137706612f7f0f8e5484236794c65772a4a063c2e327642e6ff4ce7c6dfc8ed1d5a023420f16c77431c4443cb36e0cc559837e4d5d86d654d85aa0a0
|
data/lib/rackr/action.rb
CHANGED
|
@@ -16,6 +16,16 @@ class Rackr
|
|
|
16
16
|
json: lambda do |val, status: 200, headers: {}, json: nil|
|
|
17
17
|
val = Oj.dump(val, mode: :compat) unless val.is_a?(String)
|
|
18
18
|
[status, { 'content-type' => 'application/json', 'content-length' => val.bytesize.to_s }.merge(headers), [val]]
|
|
19
|
+
end,
|
|
20
|
+
res: lambda do |val, status: nil, headers: nil, res: nil|
|
|
21
|
+
val.status = status if status
|
|
22
|
+
headers.each { |h, v| val.set_header(h, v) } if headers
|
|
23
|
+
val.finish
|
|
24
|
+
end,
|
|
25
|
+
response: lambda do |val, status: nil, headers: nil, response: nil|
|
|
26
|
+
val.status = status if status
|
|
27
|
+
headers.each { |h, v| val.set_header(h, v) } if headers
|
|
28
|
+
val.finish
|
|
19
29
|
end
|
|
20
30
|
}.freeze
|
|
21
31
|
|
data/lib/rackr.rb
CHANGED
|
@@ -18,6 +18,11 @@ class Rackr
|
|
|
18
18
|
|
|
19
19
|
def call(&block)
|
|
20
20
|
instance_eval(&block)
|
|
21
|
+
puts "\n= Routes =============="
|
|
22
|
+
routes.each_pair { |v| p v }
|
|
23
|
+
puts "\n= Config =============="
|
|
24
|
+
puts config
|
|
25
|
+
puts "\n"
|
|
21
26
|
|
|
22
27
|
@router
|
|
23
28
|
end
|
|
@@ -61,35 +66,50 @@ class Rackr
|
|
|
61
66
|
end
|
|
62
67
|
end
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const_name = name.to_s.capitalize
|
|
67
|
-
id ||= :id
|
|
69
|
+
def resources(name, id: :id, before: [], after: [], &block)
|
|
70
|
+
@resource_namespace = (@resource_namespace || []).push([name.to_s.capitalize])
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
get_const = ->(type, action) do
|
|
73
|
+
if Object.const_defined?("#{type}::#{@resource_namespace.join('::')}::#{action}")
|
|
74
|
+
Object.const_get("#{type}::#{@resource_namespace.join('::')}::#{action}")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
actions = {
|
|
79
|
+
index: { method: :get, path: nil, action: get_const.call('Actions', 'Index') },
|
|
80
|
+
new: { method: :get, path: 'new', action: get_const.call('Actions', 'New') },
|
|
81
|
+
create: { method: :post, path: nil, action: get_const.call('Actions', 'Create') },
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
actions_for_id = {
|
|
85
|
+
show: { method: :get, path: nil, action: get_const.call('Actions', 'Show') },
|
|
86
|
+
edit: { method: :get, path: "edit", action: get_const.call('Actions', 'Edit') },
|
|
87
|
+
update: { method: :put, path: nil, action: get_const.call('Actions', 'Update') },
|
|
88
|
+
delete: { method: :delete, path: nil, action: get_const.call('Actions', 'Delete') }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
block_for_id = proc do
|
|
92
|
+
actions_for_id.each do |_, definition|
|
|
93
|
+
send(definition[:method], definition[:path], definition[:action]) if definition[:action]
|
|
85
94
|
end
|
|
86
95
|
|
|
87
|
-
if
|
|
88
|
-
|
|
96
|
+
instance_eval(&block) if block_given?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
scope(name.to_s, before:, after:) do
|
|
100
|
+
actions.each do |_, definition|
|
|
101
|
+
send(definition[:method], definition[:path], definition[:action]) if definition[:action]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
assign_callback = get_const.call('Callbacks', 'Assign')
|
|
105
|
+
if assign_callback
|
|
106
|
+
scope(id.to_sym, before: assign_callback, &block_for_id)
|
|
89
107
|
else
|
|
90
|
-
scope(id.to_sym, &
|
|
108
|
+
scope(id.to_sym, &block_for_id)
|
|
91
109
|
end
|
|
92
110
|
end
|
|
111
|
+
|
|
112
|
+
@resource_namespace = @resource_namespace.first(@resource_namespace.size - 1)
|
|
93
113
|
end
|
|
94
114
|
|
|
95
115
|
HTTP_METHODS.each do |http_method|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rackr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.63
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrique F. Teixeira
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-10-
|
|
10
|
+
date: 2025-10-14 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: erubi
|