pult 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 308b0fe9ee50de08f18432fac828b5ae189dfed04ca360b7c8b11603cc19c1bc
4
- data.tar.gz: 605d8aad93efe084bedeb919c2e4375ca6948a73bd2bfe2b3274ab95351e4a76
3
+ metadata.gz: de6f2c05929b5d4e99b1ce3c73ecd398548d3319d1b82f30279b4265a53db66d
4
+ data.tar.gz: 2f141819fd1a3d1568e120102c504bddb8165dd70d0cf7307898dde33ee36880
5
5
  SHA512:
6
- metadata.gz: c226cd807dc31fa6b21dd95dc225cb4a7139359c7be7bfb510a1e7f89e356f0ea86dfff7fe2ab38f98417ea13ad268fae37536b99173ec2a8ffba267150a40c9
7
- data.tar.gz: d5045206075175c80afe8448dd5d6d4462efecc60e80572d0c42340f9271f49ae2539433b9bae2ddd93ccf6a8b1d58c142b64f5f44c46874c0ce2221e56742eb
6
+ metadata.gz: 996dda774d0419509a11f34b12bf0ee18f05134d4adabf62df95fe7e4a11d6921e4f4acd9e4389d1343d4d80126b83680e3b1d95e06fee40811fc7896adbe175
7
+ data.tar.gz: c59c2d33525f1f80dd9832bb6948962572f9f262f503cf8d652e2af15be6b453361f5af3c9b7d09cc191b13c03f0a5cd81d34711ced1a2dc31f84f0d88958d45
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.0.16] - 2019-19-09
8
+ ### Status
9
+ - Dev version
10
+
11
+ ### Updates
12
+ - Pattern `.pult.yml` in root of project
13
+ - Refactoring `Panel` obj (separated `App`, `Runner` modules with `Injector` and `DotAccessible`)
14
+ - Simplify `PULT_<name>` envs;
15
+ - Add `PULT_MULTIACT` env (types of multi action in panel `join` or `clone`)
16
+
7
17
  ## [0.0.15] - 2019-15-09
8
18
  ### Status
9
19
  - Dev version
data/README.md CHANGED
@@ -75,9 +75,9 @@ List of this new Pult API actions, that do some things:
75
75
  - `<action>_job` to run action in a backround
76
76
  - `<action>_out` to get STDOUT of action
77
77
  - `<action>_err` to get STDERR of action
78
- - `<action>_suc` to get STDERR of action
78
+ - `<action>_suc` to get success status of action (true or false)
79
79
 
80
- ### 1.2. Start Pult HTTP server and manage your app via API
80
+ ### 1.3. Start Pult HTTP server and manage your app via API
81
81
 
82
82
  Main principle of interact with API is:
83
83
  - `GET` method is used for **view** something
@@ -1,6 +1,6 @@
1
- # actions is a simple linux shell commands
2
-
1
+ ---
3
2
  appname:
3
+ # actions is a simple linux shell commands
4
4
  test: 'sleep 20 && echo 123'
5
5
 
6
6
  # allow combine actions of the same level
@@ -1,3 +1,9 @@
1
1
  module Pult
2
2
 
3
+ ROOT = ENV['PULT_ROOT'] || Dir.pwd
4
+ FILE = ENV['PULT_FILE'] || '.pult.yml'
5
+
6
+ PORT = ENV['PULT_PORT'] || 7070
7
+
8
+ MULTIACT = ENV['PULT_MULTIACT'] || 'join' # 'clone'
3
9
  end
@@ -1,6 +1,4 @@
1
- require_relative '../pult/version'
2
-
3
- require_relative '../pult/cli'
1
+ require_relative 'const'
4
2
 
5
3
  require_relative '../pult/api'
6
4
  require_relative '../pult/api/drawer'
@@ -12,8 +10,11 @@ require_relative '../pult/executor/screener'
12
10
  require_relative '../pult/executor/terminator'
13
11
 
14
12
  require_relative '../pult/panel/dot_accessible'
13
+ require_relative '../pult/panel/injector'
15
14
  require_relative '../pult/panel'
15
+ require_relative '../pult/panel/app/dot_accessible'
16
+ require_relative '../pult/panel/app/injector'
17
+ require_relative '../pult/panel/app'
18
+ require_relative '../pult/panel/runner/dot_accessible'
19
+ require_relative '../pult/panel/runner/injector'
16
20
  require_relative '../pult/panel/executor'
17
- require_relative '../pult/panel/injector/app'
18
- require_relative '../pult/panel/injector/panel'
19
- require_relative '../pult/panel/injector/runner'
@@ -16,14 +16,18 @@ module Pult
16
16
  end
17
17
 
18
18
  class Panel < Hash
19
+ module App
20
+ module DotAccessible; end
21
+ module Injector; end
22
+ end
23
+ module Runner
24
+ module DotAccessible; end
25
+ module Injector; end
26
+ end
19
27
  module DotAccessible; end
28
+ module Injector; end
20
29
  module Executor
21
30
  class Job < ActiveJob::Base; end
22
31
  end
23
- module Injector
24
- module App; end
25
- module Panel; end
26
- module Runner; end
27
- end
28
32
  end
29
33
  end
@@ -1,15 +1,10 @@
1
1
  class Pult::Api::Drawer
2
2
 
3
- PREFIX = ENV['PULT_API_PREFIX'] || 'api'
4
-
5
3
  format :json
6
4
 
7
- # TODO, temp turn off
8
- # prefix PREFIX
9
-
10
5
  ENV_VAR = /[A-Z][A-Z0-9]*/
11
6
 
12
- Runner = Pult::Panel::Injector::Runner
7
+ RunnerInjector = Pult::Panel::Runner::Injector
13
8
 
14
9
  @@self = self
15
10
 
@@ -39,12 +34,12 @@ class Pult::Api::Drawer
39
34
  end
40
35
 
41
36
  def action_get
42
- /^\/(?<path>.+)$/ =~ path.sub(/^\/#{PREFIX}/, '')
37
+ /^\/(?<path>.+)$/ =~ path
43
38
  @@panel._apply_path!(path, params)
44
39
  end
45
40
 
46
41
  def action_post
47
- /^\/(?<path>.+)$/ =~ path.sub(/^\/#{PREFIX}/, '')
42
+ /^\/(?<path>.+)$/ =~ path
48
43
  @@panel._apply_path!("#{path}!", params)
49
44
  end
50
45
  end
@@ -61,12 +56,12 @@ class Pult::Api::Drawer
61
56
  for action in flat_app._actions.sort.reverse
62
57
  action_url = action.gsub '.', '/'
63
58
 
64
- for injection in Runner.read_injections.sort
59
+ for injection in RunnerInjector.read_injections.sort
65
60
  @@self.info_get flat_app, action, injection
66
61
  get("#{action_url}_#{injection}") { action_get }
67
62
  end
68
63
 
69
- for injection in Runner.run_injections.sort
64
+ for injection in RunnerInjector.run_injections.sort
70
65
  @@self.info_post flat_app, action, injection
71
66
  post("#{action_url}_#{injection}") { action_post }
72
67
  end
@@ -1,12 +1,10 @@
1
1
  module Pult::Api::Server
2
2
 
3
- PORT = ENV['PULT_API_PORT']&.to_i || 7070
4
-
5
3
  # temp fix curl -d ''
6
4
  METHS = WEBrick::HTTPRequest::BODY_CONTAINABLE_METHODS
7
5
  WEBrick::HTTPRequest::BODY_CONTAINABLE_METHODS = METHS - ['POST']
8
6
 
9
- def self.run! api:, port: PORT
7
+ def self.run! api:, port: Pult::PORT
10
8
  Rack::Handler::WEBrick.run api, Port: port
11
9
  end
12
10
  end
@@ -1,117 +1,75 @@
1
1
  class Pult::Panel
2
2
 
3
- include DotAccessible
4
-
5
- CONFIG_ROOT = ENV['PULT_CONFIG_ROOT'] || Dir.pwd
6
- CONFIG_FILE = ENV['PULT_CONFIG_FILE'] || 'pult.yml'
7
-
8
3
  SYS_KEYS = %w{ config }
9
4
 
10
- attr_accessor :_config_root
11
- attr_accessor :_config_file
5
+ attr_accessor :_root
6
+ attr_accessor :_file
12
7
 
13
8
  def initialize auto: true
14
- @_config_root = CONFIG_ROOT
15
- @_config_file = CONFIG_FILE
9
+ @_root = Pult::ROOT
10
+ @_file = Pult::FILE
16
11
 
17
12
  init! if auto && allow_init?
18
13
  end
19
14
 
20
15
  def init!
21
16
  if allow_init?
22
-
23
- panel_hash!
17
+ to_panel!
24
18
  else
25
19
  raise StandardError, 'Init is not allowed!'
26
20
  end
27
21
  end
28
22
 
29
- def self.app_hash! hash, panel, app
30
- array_node! hash
31
-
32
- hash.class_eval { include DotAccessible }
33
-
34
- Injector::App.inject! hash, panel, app
35
-
36
- hash.values.each do |target|
37
- app_hash!(target, panel, app) if target.is_a?(Hash)
38
- end
39
-
40
- hash
41
- end
42
-
43
- def self.array_node! hash
44
- hash.keys.each do |key|
45
- value = hash[key]
46
-
47
- case value.class.name
48
- when "Hash" then array_node! value
49
- when "Array"
50
- # clone hash
51
- # complex = {}
52
- # value.each{ |elm| complex[elm] = hash[elm] }
53
- # hash[key] = complex
54
-
55
- # combine commands
56
- hash[key] = '$(' + value.join(') && $(') + ')'
57
- end
58
- end
59
- end
60
-
61
23
  private
62
24
 
63
25
  def allow_init?
64
- true_abs_path?(@_config_file) || (!!@_config_root && !!@_config_file)
26
+ true_abs_path?(@_file) || (!!@_root && !!@_file)
65
27
  end
66
28
 
67
29
  def true_abs_path? path
68
30
  path[0] == '/' && File.exists(path)
69
31
  end
70
32
 
71
- def panel_hash!
72
- compile_hash_from_configs!
33
+ def to_panel!
34
+ compile_from_pult_files!
73
35
 
36
+ class_eval { include DotAccessible }
37
+
38
+ Injector.inject! self
39
+
40
+ make_apps!
41
+ end
42
+
43
+ def make_apps!
74
44
  @_apps = []
75
45
 
76
46
  for app_name in keys
77
47
  app = self[app_name]
48
+
78
49
  @_apps << app_name
79
50
 
80
- app_hash! app, self, app_name
51
+ App.to_app! app, self, app_name
81
52
  end
82
-
83
- class_eval { include DotAccessible }
84
-
85
- Injector::Panel.inject! self
86
53
  end
87
54
 
88
- def compile_hash_from_configs!
89
- scan = @_config_root + '/**/' + @_config_file
55
+ def compile_from_pult_files!
56
+ scan = @_root + '/**/' + @_file
90
57
 
91
- Dir[scan].each do |path|
92
- config_file = YAML.load_file(path)
58
+ Dir[scan].each do |pult_file|
59
+ pult_hash = YAML.load_file(pult_file)
93
60
 
94
- dir! config_file, path
61
+ dir! pult_hash, pult_file
95
62
 
96
- merge! config_file
63
+ merge! pult_hash
97
64
  end
98
65
  end
99
66
 
100
67
  def dir! hash, path
101
68
  app = hash.keys.first
69
+ dir = Pathname.new(path).dirname.to_s
102
70
 
103
71
  config = (hash[app]['config'] ||= {})
104
72
 
105
- dir = Pathname.new(path).dirname.to_s.gsub(/\/config$/, '')
106
-
107
73
  config['dir'] ||= dir
108
74
  end
109
-
110
- def app_hash! *args
111
- self.class.app_hash! *args
112
- end
113
-
114
- def array_node! *args
115
- self.class.array_node *args
116
- end
117
75
  end
@@ -0,0 +1,41 @@
1
+ module Pult::Panel::App
2
+
3
+ def self.to_app! hash, panel, app
4
+ multi_action! hash
5
+
6
+ hash.class_eval { include DotAccessible }
7
+
8
+ Injector.inject! hash, panel, app
9
+
10
+ hash.values.each do |target|
11
+ to_app!(target, panel, app) if target.is_a?(Hash)
12
+ end
13
+
14
+ hash
15
+ end
16
+
17
+ def self.multi_action! hash
18
+ hash.keys.each do |key|
19
+ value = hash[key]
20
+
21
+ case value.class.name
22
+
23
+ when "Hash"
24
+ multi_action! value
25
+
26
+ when "Array"
27
+ case Pult::MULTIACT
28
+
29
+ when 'clone'
30
+ clone hash
31
+ complex = {}
32
+ value.each{ |elm| complex[elm] = hash[elm] }
33
+ hash[key] = complex
34
+
35
+ when 'join'
36
+ hash[key] = '$(' + value.join(') && $(') + ')'
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,59 @@
1
+ module Pult::Panel::App::DotAccessible
2
+
3
+ RunnerInjector = Pult::Panel::Runner::Injector
4
+
5
+ JOB_KEY = '_job'
6
+
7
+ class Job < ActiveJob::Base
8
+ def perform block_id
9
+ ObjectSpace._id2ref(block_id).call
10
+ end
11
+ end
12
+
13
+ def method_missing meth, *args
14
+ /(?<action>[^\!]+)(?<need_execute>\!?)/ =~ meth.to_s
15
+
16
+ for injection in [JOB_KEY] + RunnerInjector.read_injections
17
+ action.gsub! /#{injection}$/, ''
18
+ break if $&
19
+ end
20
+
21
+ value = self[action]
22
+
23
+ if !need_execute.blank?
24
+ if value.respond_to? :app?
25
+ with_job? $& do
26
+ for sub_action in value.keys
27
+ value.send "#{sub_action}!", *args
28
+ end
29
+ end
30
+ else
31
+ return execute!(action, $&, *args)
32
+ end
33
+ end
34
+
35
+ $& ? nil : value
36
+ end
37
+
38
+ private
39
+
40
+ def with_job? injection, &block
41
+ job?(injection) ? Job.perform_later(block.object_id) : block.call
42
+ end
43
+
44
+ def execute! action, injection=nil, *args
45
+ job = job?(injection) ? injection : nil
46
+
47
+ runner = Pult::Panel::Executor.send "run#{job}!", self, action, *args
48
+
49
+ if injection && !job
50
+ return send("#{action}#{injection}")
51
+ else
52
+ return runner
53
+ end
54
+ end
55
+
56
+ def job? str
57
+ str == JOB_KEY
58
+ end
59
+ end
@@ -1,4 +1,4 @@
1
- module Pult::Panel::Injector::App
1
+ module Pult::Panel::App::Injector
2
2
 
3
3
  SYS_KEYS = Pult::Panel::SYS_KEYS
4
4
 
@@ -25,7 +25,7 @@ module Pult::Panel::Injector::App
25
25
  : a.merge("#{prefix}#{k}" => v)
26
26
  end
27
27
 
28
- Pult::Panel.app_hash! hash, _panel, _app
28
+ Pult::Panel::App.to_app! hash, _panel, _app
29
29
  end
30
30
 
31
31
  def _config
@@ -1,65 +1,6 @@
1
1
  module Pult::Panel::DotAccessible
2
2
 
3
- Runner = Pult::Panel::Injector::Runner
4
-
5
- JOB_KEY = '_job'
6
-
7
- module Basic
8
- def method_missing meth, *args
9
- self[meth]
10
- end
11
- end
12
-
13
- class Job < ActiveJob::Base
14
- def perform block_id
15
- ObjectSpace._id2ref(block_id).call
16
- end
17
- end
18
-
19
3
  def method_missing meth, *args
20
- /(?<action>[^\!]+)(?<need_execute>\!?)/ =~ meth.to_s
21
-
22
- for injection in [JOB_KEY] + Runner.read_injections
23
- action.gsub! /#{injection}$/, ''
24
- break if $&
25
- end
26
-
27
- value = self[action]
28
-
29
- if !need_execute.blank?
30
- if value.respond_to? :app?
31
- with_job? $& do
32
- for sub_action in value.keys
33
- value.send "#{sub_action}!", *args
34
- end
35
- end
36
- else
37
- return execute!(action, $&, *args)
38
- end
39
- end
40
-
41
- $& ? nil : value
42
- end
43
-
44
- private
45
-
46
- def with_job? injection, &block
47
- job?(injection) ? Job.perform_later(block.object_id) : block.call
48
- end
49
-
50
- def execute! action, injection=nil, *args
51
- job = job?(injection) ? injection : nil
52
-
53
- runner = Pult::Panel::Executor.send "run#{job}!", self, action, *args
54
-
55
- if injection && !job
56
- return send("#{action}#{injection}")
57
- else
58
- return runner
59
- end
60
- end
61
-
62
- def job? str
63
- str == JOB_KEY
4
+ self[meth.to_s]
64
5
  end
65
6
  end
@@ -12,9 +12,9 @@ module Pult::Panel::Executor
12
12
 
13
13
  runner = Pult::Executor.run! command, hash._config.dir, *args
14
14
 
15
- runner.class_eval { include Pult::Panel::DotAccessible::Basic }
15
+ runner.class_eval { include Pult::Panel::Runner::DotAccessible }
16
16
 
17
- Pult::Panel::Injector::Runner.inject! hash, action, runner
17
+ Pult::Panel::Runner::Injector.inject! hash, action, runner
18
18
 
19
19
  runner
20
20
  end
@@ -1,6 +1,6 @@
1
- module Pult::Panel::Injector::Panel
1
+ module Pult::Panel::Injector
2
2
 
3
- Runner = Pult::Panel::Injector::Runner
3
+ RunnerInjector = Pult::Panel::Runner::Injector
4
4
 
5
5
  def self.inject! panel
6
6
  panel.class_eval do
@@ -44,7 +44,7 @@ module Pult::Panel::Injector::Panel
44
44
  def _apply_path! path, params=nil
45
45
  params = params&.any? ? params : nil
46
46
 
47
- for postfix in _exec_flags + Runner.injections
47
+ for postfix in _exec_flags + RunnerInjector.injections
48
48
  regexp = Regexp.new("\/([^\/]+" + Regexp.escape(postfix) + ")$")
49
49
 
50
50
  path.gsub!(regexp, '')
@@ -0,0 +1,6 @@
1
+ module Pult::Panel::Runner::DotAccessible
2
+
3
+ def method_missing meth, *args
4
+ self[meth]
5
+ end
6
+ end
@@ -1,4 +1,4 @@
1
- module Pult::Panel::Injector::Runner
1
+ module Pult::Panel::Runner::Injector
2
2
 
3
3
  def self.injections
4
4
  read_injections + run_injections
@@ -1,3 +1,3 @@
1
1
  module Pult
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
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.15
4
+ version: 0.0.16
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-16 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,7 +140,7 @@ files:
140
140
  - Rakefile
141
141
  - bin/console
142
142
  - bin/setup
143
- - example/pult.yml
143
+ - example/.pult.yml
144
144
  - exe/pult
145
145
  - lib/init/boot.rb
146
146
  - lib/init/const.rb
@@ -158,11 +158,14 @@ files:
158
158
  - lib/pult/executor/terminator.rb
159
159
  - lib/pult/executor/xscreen
160
160
  - lib/pult/panel.rb
161
+ - lib/pult/panel/app.rb
162
+ - lib/pult/panel/app/dot_accessible.rb
163
+ - lib/pult/panel/app/injector.rb
161
164
  - lib/pult/panel/dot_accessible.rb
162
165
  - lib/pult/panel/executor.rb
163
- - lib/pult/panel/injector/app.rb
164
- - lib/pult/panel/injector/panel.rb
165
- - lib/pult/panel/injector/runner.rb
166
+ - lib/pult/panel/injector.rb
167
+ - lib/pult/panel/runner/dot_accessible.rb
168
+ - lib/pult/panel/runner/injector.rb
166
169
  - lib/pult/version.rb
167
170
  - pult.gemspec
168
171
  homepage: https://github.com/dmitryck/pult