Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/filesystem_explorer/router.rb
Instance Method Summary collapse
Instance Method Details
#filesystem_explorer(options = {}, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/filesystem_explorer/router.rb', line 20 def filesystem_explorer( = {}, &block) route_config = FilesystemExplorer::FilesystemRouteOptions.new # Copy all applicable options from the parameter hash to the object %w(path as url).each do |option| route_config.send option, [option.to_sym] if [option.to_sym] && route_config.respond_to?(option) end route_config.instance_eval &block if block FilesystemExplorer::Engine.[route_config.url] ||= route_config FilesystemExplorer.routes << route_config Rails.application.routes.draw do # Download route = { "#{route_config.url}/*path/download" => "filesystem_explorer/application#download" } [:as] = :"#{route_config.as}_download" if route_config.as get # Dynamic route = { "#{route_config.url}/*path" => "filesystem_explorer/application#index" } get # Root route = { "#{route_config.url}" => "filesystem_explorer/application#index" } [:as] = :"#{route_config.as}" if route_config.as get end end |
#filesystem_routes(&block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/filesystem_explorer/router.rb', line 4 def filesystem_routes(&block) FilesystemExplorer.routes.clear config_file_path = Rails.root.join('config', 'filesystem_explorer.yml') if File.exists?(config_file_path) config_data = YAML.load_file(config_file_path) config_data.each do |route| filesystem_explorer path: route[:path] || route['path'], as: route[:as] || route['as'], url: route[:url] || route['url'] end end block.call(FilesystemExplorer::Engine. || {}) if block end |