Module: Pult::Panel::Injector

Defined in:
lib/init/struct.rb,
lib/pult/panel/injector.rb

Constant Summary collapse

RunnerInjector =
Pult::Panel::Runner::Injector

Class Method Summary collapse

Class Method Details

.inject!(panel) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
57
58
59
60
61
62
# 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