Class: Pult::Api::Drawer
- Inherits:
-
Grape::API
- Object
- Grape::API
- Pult::Api::Drawer
- Defined in:
- lib/init/struct.rb,
lib/pult/api/drawer.rb
Constant Summary collapse
- ENV_VAR =
/[A-Z][A-Z0-9]*/
- RunnerInjector =
Pult::Panel::Runner::Injector
- UI =
{ red: ->(s){'<span style="color: red;">'+ s +'</span>'}, icon: { job: '<b>‣ RUN JOB</b>', run: '<b>‣ RUN</b>', sep: ' | ', }, title: { get: ->{"#{@@injection}#{@@action_title}"}, post: ->{"#{@@injection}#{@@action_title} #{@@icon}"}, }, detail: { get: ->{"#{@@injection}#{@@action_title}<br>#{@@command}"}, post: ->{"#{@@injection}#{@@action_title}<br>#{UI[:red].(@@command)}"} } }
- @@self =
self
Class Method Summary collapse
- .draw!(panel) ⇒ Object
- .info(flat_app, action, injection, job, type:) ⇒ Object
- .info_get(flat_app, action, injection = nil, job: nil) ⇒ Object
- .info_post(flat_app, action, injection = nil, job: nil) ⇒ Object
- .parameters ⇒ Object
Class Method Details
.draw!(panel) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pult/api/drawer.rb', line 47 def self.draw! panel @@panel = panel for app in @@panel._apps resource app do flat_app = @@panel[app]._to_flat.merge!(@@panel[app]) for action in flat_app._actions.sort.reverse action_url = action.gsub '.', '/' for injection in RunnerInjector.read_injections.sort @@self.info_get flat_app, action, injection get("#{action_url}_#{injection}") { action_get } end for injection in RunnerInjector.run_injections.sort @@self.info_post flat_app, action, injection post("#{action_url}_#{injection}") { action_post } end @@self.info_get flat_app, action get(action_url) { action_get } @@self.info_post flat_app, action post(action_url) { action_post } end for action in flat_app._actions.sort.reverse action_url = action.gsub '.', '/' @@self.info_post flat_app, action, job: true post("#{action_url}_job") { action_post } end end end end |
.info(flat_app, action, injection, job, type:) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pult/api/drawer.rb', line 86 def self.info flat_app, action, injection, job, type: @@action = action @@action_title = flat_app._action_title(action) @@command = flat_app[action].to_s @@icon = job ? UI[:icon][:job] : UI[:icon][:run] @@injection = injection&.sub!('_', '') ? "#{injection}#{UI[:icon][:sep]}" : '' desc(UI[:title][type].call){ detail(UI[:detail][type].call) } parameters if type == :post end |
.info_get(flat_app, action, injection = nil, job: nil) ⇒ Object
114 115 116 |
# File 'lib/pult/api/drawer.rb', line 114 def self.info_get flat_app, action, injection=nil, job: nil info flat_app, action, injection, job, type: :get end |
.info_post(flat_app, action, injection = nil, job: nil) ⇒ Object
118 119 120 |
# File 'lib/pult/api/drawer.rb', line 118 def self.info_post flat_app, action, injection=nil, job: nil info flat_app, action, injection, job, type: :post end |
.parameters ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/pult/api/drawer.rb', line 98 def self.parameters params do optional :screen, type: String @@command.scan(/(?<=\$)#{ENV_VAR}/).each do |param| description = { type: String } if ! (default = `echo -n $#{param}`).blank? description.merge! default: default end requires param.to_sym, description end end end |