Module: FlowmorRouter::ActsAsRoutable::ClassMethods
- Defined in:
- lib/flowmor_router/acts_as_routable.rb
Instance Method Summary collapse
- #acts_as_routable(actor = nil, options = {}) ⇒ Object
-
#define_routable_methods(router_class) ⇒ Object
Set up reflective methods back to the router_class.
-
#initialize_router_class(actor, options) ⇒ Object
Register and assign a distinctive name to the router_class.
-
#prepare_routes ⇒ Object
Cause the routes to be redrawn unless we’re eager loading or testing In the case of eager loading, the routes will finally be drawn only after all the model files have been loaded.
-
#set_routable_scope(router_class, routable_scope) ⇒ Object
Set up the scope that can be called to get which records should be routed.
Instance Method Details
#acts_as_routable(actor = nil, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/flowmor_router/acts_as_routable.rb', line 56 def acts_as_routable(actor = nil, = {}) # juggle what was passed in to correct variables actor, = nil, actor if actor.is_a?(Hash) && == {} if actor.nil? singular_name = name.underscore.downcase.split("/").last actor = singular_name.pluralize [:controller_action] = [:controller_action] || "#{singular_name}#show" end router_class = initialize_router_class actor, set_routable_scope router_class, [:scope] define_routable_methods router_class prepare_routes end |
#define_routable_methods(router_class) ⇒ Object
Set up reflective methods back to the router_class
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/flowmor_router/acts_as_routable.rb', line 29 def define_routable_methods router_class define_method router_class.route_name_method_name do router_class.route_name self end define_method router_class.url_method_name do router_class.url self end define_method router_class.path_method_name do router_class.path self end end |
#initialize_router_class(actor, options) ⇒ Object
Register and assign a distinctive name to the router_class
16 17 18 19 20 21 |
# File 'lib/flowmor_router/acts_as_routable.rb', line 16 def initialize_router_class actor, FlowmorRouter::RouterClasses.register(actor, self, ).tap do |router_class| class_attribute router_class.named_instance self.send "#{router_class.named_instance}=", router_class end end |
#prepare_routes ⇒ Object
Cause the routes to be redrawn unless we’re eager loading or testing In the case of eager loading, the routes will finally be drawn only after all the model files have been loaded.
46 47 48 49 50 51 52 53 54 |
# File 'lib/flowmor_router/acts_as_routable.rb', line 46 def prepare_routes return if Rails.configuration.eager_load || Rails.env == "test" begin Rails.application.routes_reloader.reload! rescue SystemStackError # NOP -- Supressing Stack Level Too deep error # caused by models being loaded lazily during development mode. end end |
#set_routable_scope(router_class, routable_scope) ⇒ Object
Set up the scope that can be called to get which records should be routed
24 25 26 |
# File 'lib/flowmor_router/acts_as_routable.rb', line 24 def set_routable_scope(router_class, routable_scope) scope router_class.scope_name, routable_scope || -> {} end |