module Pult::Panel::Injector

Constants

RunnerInjector

Public Class Methods

inject!(panel) click to toggle source
# File lib/pult/panel/injector.rb, line 5
def self.inject! panel
  panel.class_eval do
    attr_reader :_root
    attr_reader :_apps
  end

  panel.instance_eval do
    def panel?
      true
    end

    def _ui_apps order: :az
      resproc = proc { |app| [app, _app_title(app)] }
      tapps = _translated_apps

      case order
      when :az
        _apps.sort.map(&resproc)
      when :az_ui
        _actions.map(&resproc).sort_by{|arr| tapps.index(arr[1]) }
      end
    end

    def _translated_apps
      _apps.each { |app| _app_title(app) }
    end

    def _app_title app
      _app_translate(app) || app
    end

    def _app_translate app
      self[app].config&.ui&.ru&.title
    end

    def _apply_path path
      path.split('/').reduce(self, :[])
    end

    def _apply_path! path, params=nil
      params = params&.any? ? params : nil

      for postfix in _exec_flags + RunnerInjector.injections
        regexp = Regexp.new("\/([^\/]+" + Regexp.escape(postfix) + ")$")

        path.gsub!(regexp, '')

        return _apply_path(path).send(*[$1, params].compact) if $1
      end

      _apply_path(path)
    end

    def _exec_flags
      %w{ ! }
    end
  end
end

Public Instance Methods

_app_title(app) click to toggle source
# File lib/pult/panel/injector.rb, line 32
def _app_title app
  _app_translate(app) || app
end
_app_translate(app) click to toggle source
# File lib/pult/panel/injector.rb, line 36
def _app_translate app
  self[app].config&.ui&.ru&.title
end
_apply_path(path) click to toggle source
# File lib/pult/panel/injector.rb, line 40
def _apply_path path
  path.split('/').reduce(self, :[])
end
_apply_path!(path, params=nil) click to toggle source
# File lib/pult/panel/injector.rb, line 44
def _apply_path! path, params=nil
  params = params&.any? ? params : nil

  for postfix in _exec_flags + RunnerInjector.injections
    regexp = Regexp.new("\/([^\/]+" + Regexp.escape(postfix) + ")$")

    path.gsub!(regexp, '')

    return _apply_path(path).send(*[$1, params].compact) if $1
  end

  _apply_path(path)
end
_exec_flags() click to toggle source
# File lib/pult/panel/injector.rb, line 58
def _exec_flags
  %w{ ! }
end
_translated_apps() click to toggle source
# File lib/pult/panel/injector.rb, line 28
def _translated_apps
  _apps.each { |app| _app_title(app) }
end
_ui_apps(order: :az) click to toggle source
# File lib/pult/panel/injector.rb, line 16
def _ui_apps order: :az
  resproc = proc { |app| [app, _app_title(app)] }
  tapps = _translated_apps

  case order
  when :az
    _apps.sort.map(&resproc)
  when :az_ui
    _actions.map(&resproc).sort_by{|arr| tapps.index(arr[1]) }
  end
end
panel?() click to toggle source
# File lib/pult/panel/injector.rb, line 12
def panel?
  true
end