nonnative 1.45.0 → 1.46.0

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: 85f5fe8fb5f61dce67f48ddf86ea0d2b76a6446e0e249af0f5afd22229bf3d3d
4
- data.tar.gz: 178d46b667d50d4f8b68b0e18946ca2aa265e41fd3f8c869229a6e464ddf6e41
3
+ metadata.gz: 5ab3f3907cd50fe1984cc57c28da9a17612beba23d73e8e82111ab133569a082
4
+ data.tar.gz: 71601b678ec6a2dbf53a1a2347955c691619dcf7310224d974d0b84bdc4de922
5
5
  SHA512:
6
- metadata.gz: 782d41b50946ad3741bdf1deedaff39c47db9d890d00f6e2d3ea854c8dff0a9ca3e96d3960f6e2c9d8776b41f4dc6170ca7d0fd65fb86fb65809922258b9f2df
7
- data.tar.gz: 317a75048db20140a4cd99dfc87ab8001fa4bcbfda7fc750fc3fb00ab8bfb7f7e25e16a38be17faff2c100c683281fac4f1fa9054cc4a39f510baabf6f174bb6
6
+ metadata.gz: 0bcee6e1dfcba57e0a6be43cff1be649f9fcff7c1ec94a26cca48e47b1ae0d734a279ff61464acdca5e531ba4abfb79479a9f473bd893f63d97efa575b7387e4
7
+ data.tar.gz: 91d0a695d1d2efc013af95e4a10db2637c8d47dfa21ab49a0765098f7f69c34520e514598aadca2652d69610b7baeea76822388c6030f33b3f0c78c33ec039ea
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.46.0](https://github.com/alexfalkowski/nonnative/compare/v1.45.0...v1.46.0) (2021-05-10)
6
+
7
+
8
+ ### Features
9
+
10
+ * add loading config through configure ([#87](https://github.com/alexfalkowski/nonnative/issues/87)) ([a95e8b6](https://github.com/alexfalkowski/nonnative/commit/a95e8b6817380afd732d0aefb170726f905548cb))
11
+
5
12
  ## [1.45.0](https://github.com/alexfalkowski/nonnative/compare/v1.44.1...v1.45.0) (2021-05-10)
6
13
 
7
14
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nonnative (1.45.0)
4
+ nonnative (1.46.0)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.5)
6
6
  cucumber (>= 6, < 7)
7
7
  grpc (>= 1, < 2)
data/README.md CHANGED
@@ -108,7 +108,9 @@ Then load the file with
108
108
  ```ruby
109
109
  require 'nonnative'
110
110
 
111
- Nonnative.load_configuration('configuration.yml')
111
+ Nonnative.configure do |config|
112
+ config.load_file('configuration.yml')
113
+ end
112
114
  ```
113
115
 
114
116
  ### Servers
@@ -189,7 +191,9 @@ Then load the file with:
189
191
  ```ruby
190
192
  require 'nonnative'
191
193
 
192
- Nonnative.load_configuration('configuration.yml')
194
+ Nonnative.configure do |config|
195
+ config.load_file('configuration.yml')
196
+ end
193
197
  ```
194
198
 
195
199
  #### HTTP
@@ -255,7 +259,9 @@ Then load the file with:
255
259
  ```ruby
256
260
  require 'nonnative'
257
261
 
258
- Nonnative.load_configuration('configuration.yml')
262
+ Nonnative.configure do |config|
263
+ config.load_file('configuration.yml')
264
+ end
259
265
  ```
260
266
 
261
267
  #### gRPC
@@ -317,7 +323,9 @@ Then load the file with:
317
323
  ```ruby
318
324
  require 'nonnative'
319
325
 
320
- Nonnative.load_configuration('configuration.yml')
326
+ Nonnative.configure do |config|
327
+ config.load_file('configuration.yml')
328
+ end
321
329
  ```
322
330
 
323
331
  ### Services
@@ -363,7 +371,9 @@ Then load the file with
363
371
  ```ruby
364
372
  require 'nonnative'
365
373
 
366
- Nonnative.load_configuration('configuration.yml')
374
+ Nonnative.configure do |config|
375
+ config.load_file('configuration.yml')
376
+ end
367
377
  ```
368
378
 
369
379
  #### Proxies
data/lib/nonnative.rb CHANGED
@@ -60,10 +60,6 @@ module Nonnative
60
60
  Nonnative::GoCommand.new(exec, output).executable(cmd, params)
61
61
  end
62
62
 
63
- def load_configuration(path)
64
- @configuration ||= Nonnative::Configuration.load_file(path) # rubocop:disable Naming/MemoizedInstanceVariableName
65
- end
66
-
67
63
  def configuration
68
64
  @configuration ||= Nonnative::Configuration.new
69
65
  end
@@ -2,87 +2,6 @@
2
2
 
3
3
  module Nonnative
4
4
  class Configuration
5
- class << self
6
- def load_file(path)
7
- file = YAML.load_file(path)
8
-
9
- new.tap do |c|
10
- c.strategy = file['strategy']
11
-
12
- processes(file, c)
13
- servers(file, c)
14
- services(file, c)
15
- end
16
- end
17
-
18
- private
19
-
20
- def processes(file, config)
21
- processes = file['processes'] || []
22
- processes.each do |fd|
23
- config.process do |d|
24
- d.name = fd['name']
25
- d.command = command(fd)
26
- d.timeout = fd['timeout']
27
- d.port = fd['port']
28
- d.log = fd['log']
29
- d.signal = fd['signal']
30
-
31
- proxy d, fd['proxy']
32
- end
33
- end
34
- end
35
-
36
- def command(process)
37
- go = process['go']
38
- if go
39
- Nonnative.go_executable(go['output'], go['executable'], go['command'], *go['parameters'])
40
- else
41
- process['command']
42
- end
43
- end
44
-
45
- def servers(file, config)
46
- servers = file['servers'] || []
47
- servers.each do |fd|
48
- config.server do |s|
49
- s.name = fd['name']
50
- s.klass = Object.const_get(fd['class'])
51
- s.timeout = fd['timeout']
52
- s.port = fd['port']
53
- s.log = fd['log']
54
-
55
- proxy s, fd['proxy']
56
- end
57
- end
58
- end
59
-
60
- def services(file, config)
61
- services = file['services'] || []
62
- services.each do |fd|
63
- config.service do |s|
64
- s.name = fd['name']
65
- s.timeout = fd['timeout']
66
- s.port = fd['port']
67
- s.log = fd['log']
68
-
69
- proxy s, fd['proxy']
70
- end
71
- end
72
- end
73
-
74
- def proxy(server, proxy)
75
- return unless proxy
76
-
77
- server.proxy = {
78
- type: proxy['type'],
79
- port: proxy['port'],
80
- log: proxy['log'],
81
- options: proxy['options']
82
- }
83
- end
84
- end
85
-
86
5
  def initialize
87
6
  @strategy = Strategy.new
88
7
  @processes = []
@@ -93,6 +12,16 @@ module Nonnative
93
12
  attr_accessor :processes, :servers, :services
94
13
  attr_reader :strategy
95
14
 
15
+ def load_file(path)
16
+ file = YAML.load_file(path)
17
+
18
+ self.strategy = file['strategy']
19
+
20
+ add_processes(file)
21
+ add_servers(file)
22
+ add_services(file)
23
+ end
24
+
96
25
  def strategy=(value)
97
26
  @strategy = Strategy.new(value)
98
27
  end
@@ -117,5 +46,73 @@ module Nonnative
117
46
 
118
47
  services << service
119
48
  end
49
+
50
+ private
51
+
52
+ def add_processes(file)
53
+ processes = file['processes'] || []
54
+ processes.each do |fd|
55
+ process do |d|
56
+ d.name = fd['name']
57
+ d.command = command(fd)
58
+ d.timeout = fd['timeout']
59
+ d.port = fd['port']
60
+ d.log = fd['log']
61
+ d.signal = fd['signal']
62
+
63
+ proxy d, fd['proxy']
64
+ end
65
+ end
66
+ end
67
+
68
+ def command(process)
69
+ go = process['go']
70
+ if go
71
+ params = go['parameters'] || []
72
+ Nonnative.go_executable(go['output'], go['executable'], go['command'], *params)
73
+ else
74
+ process['command']
75
+ end
76
+ end
77
+
78
+ def add_servers(file)
79
+ servers = file['servers'] || []
80
+ servers.each do |fd|
81
+ server do |s|
82
+ s.name = fd['name']
83
+ s.klass = Object.const_get(fd['class'])
84
+ s.timeout = fd['timeout']
85
+ s.port = fd['port']
86
+ s.log = fd['log']
87
+
88
+ proxy s, fd['proxy']
89
+ end
90
+ end
91
+ end
92
+
93
+ def add_services(file)
94
+ services = file['services'] || []
95
+ services.each do |fd|
96
+ service do |s|
97
+ s.name = fd['name']
98
+ s.timeout = fd['timeout']
99
+ s.port = fd['port']
100
+ s.log = fd['log']
101
+
102
+ proxy s, fd['proxy']
103
+ end
104
+ end
105
+ end
106
+
107
+ def proxy(runner, proxy)
108
+ return unless proxy
109
+
110
+ runner.proxy = {
111
+ type: proxy['type'],
112
+ port: proxy['port'],
113
+ log: proxy['log'],
114
+ options: proxy['options']
115
+ }
116
+ end
120
117
  end
121
118
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nonnative
4
- VERSION = '1.45.0'
4
+ VERSION = '1.46.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nonnative
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.45.0
4
+ version: 1.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Falkowski