flowmor_router 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/flowmor_router/acts_as_routable.rb +35 -18
- data/lib/flowmor_router/version.rb +1 -1
- data/test/dummy/log/test.log +4086 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/-gEJOwfITrtpEVkgIw1L_xmLNBm41bpwh2P5_rp-woc.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/061nPawbo6OmA521kVzzv5o6bVu_Y8H5ho6J7RR1eLk.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/1CZ1RV5wrl0_8pWkVPr4TmCdhFwdlsfaSUud-poHkvM.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/1VBNy1IsJ3Z_D0PTYedCvyj4Elo4jxPiIi9Q1aWRPV8.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/5J2BFIwNdTkQn8oGcY7uXVN-KFDQR8at6QdsXk3u3rI.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/5bcbRA8k1pi0Gbb50vS-omOrCxZcGN4u-0nheKBUVvc.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/BhfC-Z8hUI2g3RiyEjUfcbsMQs6J8pVWYuzB-3DO4Ps.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/CuEgJMSoAewC7X7Zq8Cm-22qPr3r4f44rrf0X4UekgQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Cvxc2J0WW52iPY0QfbvNQk-7SOvKifE5dGM6aHOkO1M.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/DA80XDAQYQRVyJh6rGZEl7zlAsmaeUQgoKvJ1pF52fA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/DYbtGLwz2zopQ1sFYKhdJsEPsXGrCVq4DB4-h1I-Gvw.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/FXfvlWWutm3zYOF2F9rCKcZbbS9xduR36vcncHlh-0M.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/GgujIGBFU57YccJtEUa2SnYWgiMy_bVEYZf3vFEwqHw.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/HC5njS1-RcdLk_HaYU4gV7vf7mS_LCh5jGt4eQghoWU.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/HSICbEKrxuqsJ8mHc5HdYbW63KPpB5fcalG-ncB9nfA.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/K74Pq-4b1QZYqH158k2vmKXB0GRebz4JEy1wYQ7InUs.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/K7xtMwoRibU0d8Xy7xB3UlyKGK9UKYCfyD0k2vnrRNA.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/KPTFQ23wNqiY5kyGDM8oSFGfW4r5iF9siPE67sjeLZw.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Lvda6a5KpE-3PFkMDPJojW_Ta2AMXy5L9wOFwvrH4wQ.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/M_NLHRKl_6_pWy0NQ6jYvLeCincnPgdh9i7IPjzYyII.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/Y7JM-B0JDmmxLTq5MC7Icg0yWXTmSqNDXVm6tX7XtQg.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/bK18wX-fyQGTeWcrZjSk3OvyNmdJ3j9S5es8XJnVjwU.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/cDrUZBpysDFOv_yAgZtV-hFW6yfny3Cm34n-6gjtMdc.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/dA9Dte78y4FMBvx3GvtNajeV6J_ROiHnHGDBs7jORNA.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/dj5ct1LV1VgTI3byhW6dlfYS5pRZMCKePo9Izu92SNY.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/h14KwG-Dn7vk4kuGyh8j7vqZBBnYp3kQEJRydovyrFk.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/jY5qibYZx-JfvgKFMQ718JacjcxANGHrJsTsXQVYj1Q.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/lIaofasM7f3m5AXVk0kcxEOFnC-3amsr4Xo0HlboaHI.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/mJZ6zLA8w_-3K12hQEGUa5sLQ27FmACK_aFxgt-EsdQ.cache +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/p-bXAF8X0ORyZWU5uCO5R7F71cebc2I9L9dDz0Zcjec.cache +2 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/pDY98sUMpZNsoftp1YtaO0Al1zODRyB1Vvt5960LRC8.cache +1 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/v3.0/xW7Uyqk2ae33PhlMnd7cJHCWKEcgBwMpNQuEgvBDGp8.cache +2 -0
- metadata +66 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2354bf0ab26b01a8f2d1546ae024da7cfa33cc
|
4
|
+
data.tar.gz: 1dd80804e5c591fab85ec55ef55b0c59d423cf04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4122bdc8691dd32566a1c78056203966b1a11e94affae85b1e174d3cec2cdd818c5a0a9397f5b8eb39b823b8df13c39fc4349d7026824da1e7774fc4d2b4911
|
7
|
+
data.tar.gz: 85053464da6bdc9e2043bffe62d4c54e18590a528717f1bc1987e468d7bf246bb7b12ea397c567542dd7c1e08a61603399dedc393819486cdd69c4e1abf3c6ff
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Flowmor Router
|
2
2
|
|
3
|
-
|
3
|
+
Flowmor Router is a Rails::Engine that enables ActiveRecord Models to route themselves in Rails 4.x applications. For example:
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
class Post < ActiveRecord::Base
|
@@ -3,7 +3,6 @@ module FlowmorRouter
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
6
|
after_save :reload_routes
|
8
7
|
|
9
8
|
def reload_routes
|
@@ -13,22 +12,21 @@ module FlowmorRouter
|
|
13
12
|
|
14
13
|
module ClassMethods
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
actor,
|
19
|
-
|
20
|
-
|
21
|
-
actor = singular_name.pluralize
|
22
|
-
options[:controller_action] = options[:controller_action] || "#{singular_name}#show"
|
15
|
+
# Register and assign a distinctive name to the router_class
|
16
|
+
def initialize_router_class actor, options
|
17
|
+
FlowmorRouter::RouterClasses.register(actor, self, options).tap do |router_class|
|
18
|
+
class_attribute router_class.named_instance
|
19
|
+
self.send "#{router_class.named_instance}=", router_class
|
23
20
|
end
|
24
|
-
|
25
|
-
# Register and assign a distinctive name to the router_class
|
26
|
-
router_class = FlowmorRouter::RouterClasses.register(actor, self, options)
|
27
|
-
class_attribute router_class.named_instance
|
28
|
-
self.send "#{router_class.named_instance}=", router_class
|
21
|
+
end
|
29
22
|
|
30
|
-
|
23
|
+
# Set up the scope that can be called to get which records should be routed
|
24
|
+
def set_routable_scope(router_class, routable_scope)
|
25
|
+
scope router_class.scope_name, routable_scope || -> {}
|
26
|
+
end
|
31
27
|
|
28
|
+
# Set up reflective methods back to the router_class
|
29
|
+
def define_routable_methods router_class
|
32
30
|
define_method router_class.route_name_method_name do
|
33
31
|
router_class.route_name self
|
34
32
|
end
|
@@ -40,16 +38,35 @@ module FlowmorRouter
|
|
40
38
|
define_method router_class.path_method_name do
|
41
39
|
router_class.path self
|
42
40
|
end
|
43
|
-
|
41
|
+
end
|
42
|
+
|
43
|
+
# Cause the routes to be redrawn unless we're eager loading or testing
|
44
|
+
# In the case of eager loading, the routes will finally be drawn only after
|
45
|
+
# all the model files have been loaded.
|
46
|
+
def prepare_routes
|
47
|
+
return if Rails.configuration.eager_load || Rails.env == "test"
|
44
48
|
begin
|
45
|
-
|
46
|
-
Rails.application.routes_reloader.reload!
|
47
|
-
end
|
49
|
+
Rails.application.routes_reloader.reload!
|
48
50
|
rescue SystemStackError
|
49
51
|
# NOP -- Supressing Stack Level Too deep error
|
50
52
|
# caused by models being loaded lazily during development mode.
|
51
53
|
end
|
52
54
|
end
|
55
|
+
|
56
|
+
def acts_as_routable(actor = nil, options = {})
|
57
|
+
# juggle what was passed in to correct variables
|
58
|
+
actor, options = nil, actor if actor.is_a?(Hash) && options == {}
|
59
|
+
if actor.nil?
|
60
|
+
singular_name = name.underscore.downcase.split("/").last
|
61
|
+
actor = singular_name.pluralize
|
62
|
+
options[:controller_action] = options[:controller_action] || "#{singular_name}#show"
|
63
|
+
end
|
64
|
+
|
65
|
+
router_class = initialize_router_class actor, options
|
66
|
+
set_routable_scope router_class, options[:scope]
|
67
|
+
define_routable_methods router_class
|
68
|
+
prepare_routes
|
69
|
+
end
|
53
70
|
end
|
54
71
|
end
|
55
72
|
end
|