Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/ant/design/rails/routes.rb
Instance Method Summary collapse
- #antd_lambda(antd_route_without_api, antd_route) ⇒ Object
- #antd_pages(routes_ts_path) ⇒ Object
- #antd_route_parse(antd_api, antd_route) ⇒ Object
Instance Method Details
#antd_lambda(antd_route_without_api, antd_route) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ant/design/rails/routes.rb', line 58 def antd_lambda(antd_route_without_api, antd_route) antd_route_parts = antd_route_without_api.split("/") if antd_route["redirect"].present? lambda { get antd_route_without_api, to: redirect(antd_route["redirect"]) } elsif antd_route_parts.length == 1 lambda { get antd_route_without_api => "#{antd_route_parts.first.underscore}#index" } else lambda { get antd_route_without_api => "#{antd_route_parts.first.underscore}##{antd_route_parts[1..-1].join("_").underscore}" } end end |
#antd_pages(routes_ts_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ant/design/rails/routes.rb', line 33 def antd_pages(routes_ts_path) antd_routes_reader = ::Ant::Design::Rails::Routes.new(routes_ts_path) antd_api = {} antd_routes_reader.each do |antd_route| next if antd_route["path"] == "*" antd_route_parse(antd_api, antd_route) end scope :api do antd_api.each_value.map(&:call) end end |
#antd_route_parse(antd_api, antd_route) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ant/design/rails/routes.rb', line 45 def antd_route_parse(antd_api, antd_route) if antd_route["path"] == "/" && antd_route["redirect"].present? root to: redirect(antd_route["redirect"]) elsif (antd_route["path"][0..4]) == "/api/" && (antd_route["path"][5..-1]).present? antd_route_without_api = antd_route["path"][5..-1] antd_api[antd_route_without_api] = antd_lambda(antd_route_without_api, antd_route) end # Recurse antd_route['routes']&.each do |sub_antd_route| antd_route_parse(antd_api, sub_antd_route) end end |