Module: OFA
- Defined in:
- lib/plugin_helper.rb
Class Method Summary collapse
-
.add_route(method, path, &block) ⇒ Object
Helper for plugins to add routes easily.
- .apply_pending_routes(router) ⇒ Object
- .on_boot(&block) ⇒ Object
- .run_boot_hooks ⇒ Object
Class Method Details
.add_route(method, path, &block) ⇒ Object
Helper for plugins to add routes easily
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/plugin_helper.rb', line 16 def self.add_route(method, path, &block) # This assumes ROUTES is available globally (defined in config.ru) # If not, we might need a different registration mechanism if defined?(ROUTES) ROUTES.send(method, path, &block) else # Delay registration if ROUTES not yet defined @pending_routes ||= [] @pending_routes << { method: method, path: path, block: block } end end |
.apply_pending_routes(router) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/plugin_helper.rb', line 28 def self.apply_pending_routes(router) return unless @pending_routes @pending_routes.each do |r| router.send(r[:method], r[:path], &r[:block]) end @pending_routes = [] end |
.on_boot(&block) ⇒ Object
7 8 9 |
# File 'lib/plugin_helper.rb', line 7 def self.on_boot(&block) @hooks[:on_boot] << block end |
.run_boot_hooks ⇒ Object
11 12 13 |
# File 'lib/plugin_helper.rb', line 11 def self.run_boot_hooks @hooks[:on_boot].each(&:call) end |