pult 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a1f2626325d559bee139156bf965999bc5f25c7bcc1982ee89d74542092873f
4
- data.tar.gz: 2746f3c883cbf0c5bfb5f8501f2b56d558d283702443bf122560d3f0f1624f1d
3
+ metadata.gz: 96037cdff4cfc27b119180d4d7945ecd6c822c5d866fbd01f1e324dabd1dcbb8
4
+ data.tar.gz: 8e8eb4befec919c2dc4df105e27d10ae9015268abc254d00c7d840c4d51a4935
5
5
  SHA512:
6
- metadata.gz: d981f88ef4ed8e86f20ec8d20e908b0596111fa9e0dda770ee66b9953554b4669162d1cc8f024d8285364af452d15550f22f2636277423e3abd84d453efe847a
7
- data.tar.gz: '08fbc15c24149cd6fdf616d60cfe769fe263585aca4dd663dbc3d4bc888ad44c9120b214adf7b2a2104f456f112ee38f3c092ac5bbd63ffb9c49e0366e411057'
6
+ metadata.gz: 55bfef5c6532e1a3ab763209873dfbecaf44c057cd48c65e21a139da50281392f16715129d6979b2830b9705b35bf20e736bcc9b89aaeb48e2e2f425b48d952d
7
+ data.tar.gz: 5e43c50166fa7ef2e360d6a516851838a3e7308bc5f193636595ae1a9b7d88004e5ad293eb8c99a130a4c045c36c6c49c32999a0e31137a72b34c94fbcec1b63
data/CHANGELOG.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Done
2
2
 
3
- - Ruby/Http interface to yml tasks (only development mode, just playground)
3
+ - Ruby/Http interface to yml tasks. Playground to 0.0.7
4
4
 
5
5
  # Fixes and updates
6
6
 
7
7
  - Fix and refactoring API
8
- - Add Swagger doc rendering
8
+ - Add JSON Swagger documentation for API
9
9
  - Ruby version req
data/lib/init/req-proj.rb CHANGED
@@ -3,7 +3,6 @@ require_relative '../pult/version'
3
3
  require_relative '../pult/cli'
4
4
 
5
5
  require_relative '../pult/api'
6
- require_relative '../pult/api/drawer/helper'
7
6
  require_relative '../pult/api/drawer'
8
7
  require_relative '../pult/api/server'
9
8
 
data/lib/init/struct.rb CHANGED
@@ -4,9 +4,7 @@ module Pult
4
4
  class Cli; end
5
5
 
6
6
  module Api
7
- class Drawer < Grape::API
8
- module Helper; end
9
- end
7
+ class Drawer < Grape::API; end
10
8
  module Server; end
11
9
  end
12
10
 
@@ -1,64 +1,123 @@
1
1
  class Pult::Api::Drawer
2
2
 
3
- format :json
4
-
5
3
  PREFIX = ENV['PULT_API_PREFIX'] || 'api'
6
4
 
5
+ format :json
6
+
7
7
  prefix PREFIX
8
8
 
9
- def self.draw! panel
10
- @@panel = panel
9
+ UI = {
10
+ red: ->(s){'<span style="color: red;">'+ s +'</span>'},
11
+
12
+ icon: {
13
+ job: '<b>&#8227; RUN JOB</b>',
14
+ run: '<b>&#8227; RUN</b>',
15
+ sep: ' | ',
16
+ },
17
+
18
+ title: {
19
+ get: ->{"#{@@injection}#{@@action_title}"},
20
+ post: ->{"#{@@injection}#{@@action_title} #{@@icon}"},
21
+ },
22
+
23
+ detail: {
24
+ get: ->{"#{@@injection}#{@@action_title}<br>#{@@command}"},
25
+ post: ->{"#{@@injection}#{@@action_title}<br>#{UI[:red].(@@command)}"}
26
+ }
27
+ }
11
28
 
12
- for @@app in @@panel._apps
13
- resource @@app, & ACTIONS
29
+ helpers do
30
+ def path
31
+ route.pattern.origin
14
32
  end
15
33
 
16
- add_swagger_documentation
17
- end
34
+ def action_get
35
+ /^\/(?<path>.+)$/ =~ path.sub(/^\/#{PREFIX}/, '')
36
+ @@panel._apply_path!(path, params)
37
+ end
18
38
 
19
- include Helper
39
+ def action_post
40
+ /^\/(?<path>.+)$/ =~ path.sub(/^\/#{PREFIX}/, '')
41
+ @@panel._apply_path!("#{path}!", params)
42
+ end
43
+ end
20
44
 
21
45
  Runner = Pult::Panel::Injector::Runner
22
46
 
23
- ACTIONS = proc {
47
+ @@self = self
48
+
49
+ def self.draw! panel
50
+ @@panel = panel
24
51
 
25
- flat_app = @@panel[@@app]._to_flat.merge!(@@panel[@@app])
52
+ for app in @@panel._apps
26
53
 
27
- for action in flat_app._actions.sort.reverse
28
- action_url = action.gsub '.', '/'
54
+ resource app do
29
55
 
30
- for injection in Runner.read_injections.sort
31
- info_get flat_app, action, injection
32
- get "#{action_url}_#{injection}" do
33
- action route
34
- end
35
- end
56
+ flat_app = @@panel[app]._to_flat.merge!(@@panel[app])
57
+
58
+ for action in flat_app._actions.sort.reverse
59
+ action_url = action.gsub '.', '/'
36
60
 
37
- for injection in Runner.run_injections.sort
38
- info_post flat_app, action, injection
39
- post "#{action_url}_#{injection}" do
40
- action route
61
+ for injection in Runner.read_injections.sort
62
+ @@self.info_get flat_app, action, injection
63
+ get("#{action_url}_#{injection}") { action_get }
64
+ end
65
+
66
+ for injection in Runner.run_injections.sort
67
+ @@self.info_post flat_app, action, injection
68
+ post("#{action_url}_#{injection}") { action_post }
69
+ end
70
+
71
+ @@self.info_get flat_app, action
72
+ get(action_url) { action_get }
73
+
74
+ @@self.info_post flat_app, action
75
+ post(action_url) { action_post }
41
76
  end
42
- end
43
77
 
44
- info_get flat_app, action
45
- get action_url do
46
- action route
47
- end
78
+ for action in flat_app._actions.sort.reverse
79
+ action_url = action.gsub '.', '/'
48
80
 
49
- info_post flat_app, action
50
- post action_url do
51
- action! route
81
+ @@self.info_post flat_app, action, job: true
82
+ post("#{action_url}_job") { action_post }
83
+ end
52
84
  end
53
85
  end
86
+ end
87
+
88
+ def self.info flat_app, action, injection, job, type:
89
+ @@action = action
90
+ @@action_title = flat_app._action_title(action)
91
+ @@command = flat_app[action].to_s
92
+ @@icon = job ? UI[:icon][:job] : UI[:icon][:run]
93
+ @@injection = injection&.sub!('_', '') ? "#{injection}#{UI[:icon][:sep]}" : ''
94
+
95
+ desc(UI[:title][type].call){ detail(UI[:detail][type].call) }
96
+
97
+ parameters if type == :post
98
+ end
99
+
100
+ def self.parameters
101
+ params do
102
+ optional :screen, type: String
54
103
 
55
- for action in flat_app._actions.sort.reverse
56
- action_url = action.gsub '.', '/'
104
+ @@command.scan(/(?<=\$)[^\s()]+/).each do |param|
105
+ description = { type: String }
57
106
 
58
- info_post flat_app, action, job: true
59
- post "#{action_url}_job" do
60
- action! route
107
+ if ! (default = `echo -n $#{param}`).blank?
108
+ description.merge! default: default
109
+ end
110
+
111
+ requires param.to_sym, description
61
112
  end
62
113
  end
63
- }
114
+ end
115
+
116
+ def self.info_get flat_app, action, injection=nil, job: nil
117
+ info flat_app, action, injection, job, type: :get
118
+ end
119
+
120
+ def self.info_post flat_app, action, injection=nil, job: nil
121
+ info flat_app, action, injection, job, type: :post
122
+ end
64
123
  end
data/lib/pult/api.rb CHANGED
@@ -1,10 +1,14 @@
1
1
  module Pult::Api
2
2
 
3
+ API = Drawer
4
+
3
5
  def self.init! panel
4
- Drawer.draw! panel
6
+ API.draw! panel
7
+
8
+ API.add_swagger_documentation
5
9
  end
6
10
 
7
11
  def self.server! *args
8
- Server.run! *args, api: Drawer
12
+ Server.run! *args, api: API
9
13
  end
10
14
  end
data/lib/pult/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pult
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pult
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - dmitryck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-08 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -147,7 +147,6 @@ files:
147
147
  - lib/pult.rb
148
148
  - lib/pult/api.rb
149
149
  - lib/pult/api/drawer.rb
150
- - lib/pult/api/drawer/helper.rb
151
150
  - lib/pult/api/server.rb
152
151
  - lib/pult/cli.rb
153
152
  - lib/pult/executor.rb
@@ -1,83 +0,0 @@
1
- module Pult::Api::Drawer::Helper
2
-
3
- def self.included base
4
- @@base = base
5
-
6
- Grape::API::Instance.extend ClassMethods
7
-
8
- base.helpers do
9
- def path
10
- route.pattern.origin
11
- end
12
-
13
- def panel
14
- @@base.class_variable_get :@@panel
15
- end
16
-
17
- def action route
18
- /^\/(?<path>.+)$/ =~ path.sub(/^\/#{@@base::PREFIX}/, '')
19
- panel._apply_path!(path, params)
20
- end
21
-
22
- def action! route
23
- /^\/(?<path>.+)$/ =~ path.sub(/^\/#{@@base::PREFIX}/, '')
24
- panel._apply_path!("#{path}!", params)
25
- end
26
- end
27
- end
28
-
29
- module ClassMethods
30
- UI = {
31
- red: ->(s){'<span style="color: red;">'+ s +'</span>'},
32
- icon: {
33
- job: '<b>&#8227; RUN JOB</b>',
34
- run: '<b>&#8227; RUN</b>',
35
- sep: ' | ',
36
- },
37
- title: {
38
- get: ->{"#{@@injection}#{@@action_title}"},
39
- post: ->{"#{@@injection}#{@@action_title} #{@@icon}"},
40
- },
41
- detail: {
42
- get: ->{"#{@@injection}#{@@action_title}<br>#{@@command}"},
43
- post: ->{"#{@@injection}#{@@action_title}<br>#{UI[:red].(@@command)}"}
44
- }
45
- }
46
-
47
- def info flat_app, action, injection, job, type:
48
- @@action = action
49
- @@action_title = flat_app._action_title(action)
50
- @@command = flat_app[action].to_s
51
- @@icon = job ? UI[:icon][:job] : UI[:icon][:run]
52
- @@injection = injection&.sub!('_', '') ? "#{injection}#{UI[:icon][:sep]}" : ''
53
-
54
- desc(UI[:title][type].call){ detail(UI[:detail][type].call) }
55
-
56
- parameters if type == :post
57
- end
58
-
59
- def parameters
60
- params do
61
- optional :screen, type: String
62
-
63
- @@command.scan(/(?<=\$)[^\s()]+/).each do |param|
64
- description = { type: String }
65
-
66
- if ! (default = `echo -n $#{param}`).blank?
67
- description.merge! default: default
68
- end
69
-
70
- requires param.to_sym, description
71
- end
72
- end
73
- end
74
-
75
- def info_get flat_app, action, injection=nil, job: nil
76
- info flat_app, action, injection, job, type: :get
77
- end
78
-
79
- def info_post flat_app, action, injection=nil, job: nil
80
- info flat_app, action, injection, job, type: :post
81
- end
82
- end
83
- end