Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/filesystem_explorer/router.rb
Instance Method Summary collapse
- #filesystem_explorer(options = {}, &block) ⇒ Object
- #filesystem_explorer_route_options ⇒ Object
- #filesystem_routes(&block) ⇒ Object
Instance Method Details
#filesystem_explorer(options = {}, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/filesystem_explorer/router.rb', line 26 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 ||= {} [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_explorer_route_options ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/filesystem_explorer/router.rb', line 4 def if $filesystem_explorer_route_options.is_a?(Hash) $filesystem_explorer_route_options.empty else $filesystem_explorer_route_options = {} end end |
#filesystem_routes(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/filesystem_explorer/router.rb', line 12 def filesystem_routes(&block) 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( || {}) if block end |