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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27ddf52f9383face08d230bd0838da6ae36d9c6412cf9270a842319d46e796d7
4
- data.tar.gz: cfb51f736daf5a39b02b9176bae1af468282bc68be842f654edc40430f58245e
3
+ metadata.gz: 2b5ecbdc7264798f35f7eacbf0643a325aee0f3f48fae7f598c0f970daad547e
4
+ data.tar.gz: 3af6890ffca08d81d561aa675b3980e8c00f5a0ec9efbbf26b6d24337f7c5a78
5
5
  SHA512:
6
- metadata.gz: 0ba240aa9334e1c45123d841584cae2c0ac7c61d77f830b6845e4953c1d9c083f153be2af40e02eda681cd4eb7248c282cd9b33a51306dda068a5421c4401f87
7
- data.tar.gz: c108aaf8e8415017f5d9902f59e720e9840206551c469cb102dcb7e2472aa364fbeeeaa593e82fd990eeb20a2d49f274d3878e4b4df2232d5c7eb1ece1875651
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(*controllers)
7
- controllers.each do |controller|
8
- StaticRoutes.for(controller, self)
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
- class << self
5
- def route_from_action(action)
6
- action.to_s.gsub(/[^a-zA-Z]/, '-')
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
- def controller_from_chars(chars)
10
- "#{chars.to_s.camelize}Controller".constantize
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
- def for(controller, context)
14
- controller_constant = controller_from_chars(controller)
15
- controller_constant.instance_methods(false).each do |action|
16
- context.get(route_from_action(action), to: "#{controller}##{action}")
17
- end
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.0.4
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.3
60
+ rubygems_version: 3.0.4
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Draw static routes