Sha256: 4cc42448f6bef5914bb64588d44aa0a9aa288cc06d9b878d7fec8f964a69eb81
Contents?: true
Size: 1.63 KB
Versions: 15
Compression:
Stored size: 1.63 KB
Contents
class Navbar include Rails.application.routes.url_helpers def initialize(user) @user = user end def topbar bar('topbar') end def sidebar bar('sidebar') end def bar(key) yaml_data = YAML.load_file("#{Rails.application.root}/config/pg_rails.yml") bar_data = ActiveSupport::HashWithIndifferentAccess.new(yaml_data)[key] return [] if bar_data.blank? # rubocop:disable Security/Eval bar_data.map do |item| { title: item['name'], path: eval(item['path']), show: item['policy'] ? eval(item['policy']) : true } end # rubocop:enable Security/Eval end def all_children_hidden?(entry) entry[:children].all? { |child| child[:show] == false } end def any_children_active?(entry, request) entry[:children].any? { |child| active_entry?(child, request) } true # TODO: quitar end def hide_entry?(entry) if entry[:children].present? all_children_hidden?(entry) else entry[:show] == false end end def custom_current_page?(path, request) current_route = Rails.application.routes.recognize_path(request.env['PATH_INFO']) test_route = Rails.application.routes.recognize_path(path) current_route[:controller] == test_route[:controller] && current_route[:action] == test_route[:action] rescue ActionController::RoutingError false end def active_entry?(entry, request) if entry[:children].present? any_children_active?(entry, request) elsif entry[:path].present? custom_current_page?(entry[:path], request) end end private def policy(clase) Pundit.policy(@user, clase) end end
Version data entries
15 entries across 15 versions & 1 rubygems