Module: Karafka::Web::Ui::Helpers::PathsHelper
- Included in:
- Base
- Defined in:
- lib/karafka/web/ui/helpers/paths_helper.rb
Overview
Helper for web ui paths builders
Instance Method Summary collapse
-
#asset_path(local_path) ⇒ String
Generates a full path to any asset with our web-ui version.
-
#explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) ⇒ String
Helps build explorer paths.
-
#flatten_params(prefix, hash, result = {}) ⇒ Hash
Helper method to flatten nested hashes and arrays.
-
#root_path(*args) ⇒ String
Generates a full path with the root path out of the provided arguments.
-
#scheduled_messages_explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) ⇒ String
Helps build scheduled messages paths.
Instance Method Details
#asset_path(local_path) ⇒ String
Generates a full path to any asset with our web-ui version. We ship all assets with the version in the url to prevent those assets from being used after update. After each web-ui update, assets are going to be re-fetched as the url will change
51 52 53 |
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 51 def asset_path(local_path) root_path("assets/#{Karafka::Web::VERSION}/#{local_path}") end |
#explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) ⇒ String
Helps build explorer paths. We often link offsets to proper messages, etc so this allows us to short-track this
65 66 67 |
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 65 def explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) root_path(*['explorer', topic_name, partition_id, offset, action].compact) end |
#flatten_params(prefix, hash, result = {}) ⇒ Hash
Helper method to flatten nested hashes and arrays
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 15 def flatten_params(prefix, hash, result = {}) if hash.is_a?(Hash) hash.each do |k, v| new_prefix = prefix.empty? ? k.to_s : "#{prefix}[#{k}]" flatten_params(new_prefix, v, result) end elsif hash.is_a?(Array) hash.each_with_index do |v, i| new_prefix = "#{prefix}[#{i}]" flatten_params(new_prefix, v, result) end else result[prefix] = hash.to_s end result end |
#root_path(*args) ⇒ String
This needs to be done that way with the #root_path
because the web UI can be mounted in a sub-path and we need to make sure our all paths are relative to “our” root, not the root of the app in which it was mounted.
Generates a full path with the root path out of the provided arguments
41 42 43 |
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 41 def root_path(*args) "#{env.fetch('SCRIPT_NAME')}/#{args.join('/')}" end |
#scheduled_messages_explorer_path(topic_name = nil, partition_id = nil, offset = nil, action = nil) ⇒ String
Helps build scheduled messages paths. Similar to the explorer helper one
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/karafka/web/ui/helpers/paths_helper.rb', line 76 def ( topic_name = nil, partition_id = nil, offset = nil, action = nil ) root_path( *['scheduled_messages', 'explorer', topic_name, partition_id, offset, action].compact ) end |