draw_static 0.0.4 → 0.1.1
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/draw_static.rb +3 -4
- data/lib/static_routes.rb +42 -10
- 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: 2b5ecbdc7264798f35f7eacbf0643a325aee0f3f48fae7f598c0f970daad547e
|
4
|
+
data.tar.gz: 3af6890ffca08d81d561aa675b3980e8c00f5a0ec9efbbf26b6d24337f7c5a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b72a0c3b99c459009c7ee1546263a19483c9d18d0a708bdc7349200339e302a4ec5a572570a54a76782a2928ffd6faed8a76a96150a0ff69be1232253afb09c
|
7
|
+
data.tar.gz: a75abdb394ff578571798179491d8ecc50733aee7f05bb1d51d8a83c03695928343fea0db328e910400a972f0ad6deb3e09015e5d5d7d8f045f4981e2ffd831f
|
data/lib/draw_static.rb
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
require_relative 'static_routes'
|
4
4
|
|
5
5
|
module DrawStatic
|
6
|
-
def draw_static(*
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
def draw_static(*arguments)
|
7
|
+
generator = StaticRoutes.new(context: self)
|
8
|
+
generator.for(arguments)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
data/lib/static_routes.rb
CHANGED
@@ -1,20 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class StaticRoutes
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
attr_accessor :context, :limits
|
5
|
+
def initialize(attributes = {})
|
6
|
+
@context = attributes[:context]
|
7
|
+
@limits = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def route_from_action(action)
|
11
|
+
action.to_s.gsub(/[^a-zA-Z]/, '-')
|
12
|
+
end
|
13
|
+
|
14
|
+
def controller_from_chars(chars)
|
15
|
+
"#{chars.to_s.camelize}Controller".constantize
|
16
|
+
end
|
17
|
+
|
18
|
+
def desired_routes_from(controller)
|
19
|
+
instance_methods = controller.instance_methods(false)
|
20
|
+
if limits[:only]
|
21
|
+
limits[:only].select { |method| instance_methods.include?(method) }
|
22
|
+
else
|
23
|
+
instance_methods.reject do |route|
|
24
|
+
limits[:except]&.include?(route)
|
25
|
+
end
|
7
26
|
end
|
27
|
+
end
|
8
28
|
|
9
|
-
|
10
|
-
|
29
|
+
def for(arguments)
|
30
|
+
controllers = split_controllers_and_limits(arguments)
|
31
|
+
controllers.each do |controller|
|
32
|
+
write_routes_for(controller)
|
11
33
|
end
|
34
|
+
end
|
12
35
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
def split_controllers_and_limits(arguments)
|
39
|
+
if arguments.last.is_a? Hash
|
40
|
+
self.limits = arguments.last
|
41
|
+
return arguments[0..-2]
|
42
|
+
end
|
43
|
+
arguments
|
44
|
+
end
|
45
|
+
|
46
|
+
def write_routes_for(controller)
|
47
|
+
controller_constant = controller_from_chars(controller)
|
48
|
+
desired_routes_from(controller_constant).each do |action|
|
49
|
+
context.get(route_from_action(action), to: "#{controller}##{action}")
|
18
50
|
end
|
19
51
|
end
|
20
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: draw_static
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inou Ridder
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
rubygems_version: 3.0.
|
60
|
+
rubygems_version: 3.0.4
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Draw static routes
|