bootinq 1.4.2 → 1.7

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: 4bbde8bd5a9047488c41a60788b57c99ffba1de61217a0e5ac6613a856e5fc66
4
- data.tar.gz: 6932d67aa5b2f484726331b5f1483352bc1f6bd535ea187dabe13d7e909630ae
3
+ metadata.gz: ab4d92e0581dec34e3b8c35ab842953fc6c488a7ff7a79aab4e155e0ec04b598
4
+ data.tar.gz: 8d1b03413cb95941d3c34fa33e5167ae717a1152fb824f9fc4ca4c95232e3374
5
5
  SHA512:
6
- metadata.gz: 48c42edfe5b1a4475ad65b5cec66e6a5a124073b6aea9b6fceeea94cc76ce3ddac1786c30f4c0290cbe677e40a677e4ce4350e080867d3a8032fd36a0552d12e
7
- data.tar.gz: 95db837f38266267c0fe733edcd91ad51694ff8c5a90c849e1f28335637a385cda2de1ea1c285e5a6e8f8bb5f00be2e121b5ef27bbfe9213a3ecf17e97454c22
6
+ metadata.gz: 957af1a041fb5230543b149ae7bb3fa14b455e0070232c60afe617c6dfce34712d3d9ea118aad38d2fd824ef253cb6af38a1e4a115d9f5862a2680ce4d2a48e2
7
+ data.tar.gz: 3dcecd28f93e44b34e7401fb6c4702754f57cac19706996a74fdbc306a9251d0fd7f8360afcd07470d37627461af4ecf1ea45e03f626b52543123d1991453d72
data/Gemfile CHANGED
@@ -32,6 +32,14 @@ group :shared_boot do
32
32
  gem 'shared', path: 'spec/dummy/engines/shared'
33
33
  end
34
34
 
35
+ group :api_part_boot do
36
+ gem 'api_part', path: 'spec/dummy/engines/api_part'
37
+ end
38
+
35
39
  group :api_boot do
36
40
  gem 'api', path: 'spec/dummy/engines/api'
41
+ end
42
+
43
+ group :api2_boot do
44
+ gem 'api2', path: 'spec/dummy/engines/api2'
37
45
  end
data/README.md CHANGED
@@ -148,7 +148,7 @@ require 'bootinq'
148
148
 
149
149
  # Bundler.require :default, ENV['RACK_ENV']
150
150
  Bootinq.require :default, ENV['RACK_ENV'], verbose: true
151
-
151
+ ```
152
152
 
153
153
  ## Development
154
154
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bootinq
4
- VERSION = "1.4.2"
4
+ VERSION = "1.7"
5
5
  end
data/lib/bootinq.rb CHANGED
@@ -37,7 +37,7 @@ require "bootinq/switch"
37
37
  # == Example <tt>config/bootinq.yml</tt>:
38
38
  #
39
39
  # env_key: BOOTINQ
40
- # default: "-f"
40
+ # default: a
41
41
  #
42
42
  # parts:
43
43
  # s: :shared
@@ -45,6 +45,11 @@ require "bootinq/switch"
45
45
  # mount:
46
46
  # a: :api
47
47
  # f: :engine
48
+ #
49
+ # deps:
50
+ # shared:
51
+ # in: af
52
+ #
48
53
  class Bootinq
49
54
  include Singleton
50
55
 
@@ -52,18 +57,24 @@ class Bootinq
52
57
  "env_key" => 'BOOTINQ',
53
58
  "default" => '',
54
59
  "parts" => {},
55
- "mount" => {}
60
+ "mount" => {},
61
+ "deps" => {}
56
62
  }.freeze
57
63
 
58
- class << self
59
- protected def delegated(sym) # :no-doc:
60
- location = caller_locations(1, 1).first
61
- file, line = location.path, location.lineno
62
- definiton = %(def self.#{sym}(*args, &block); instance.#{sym}(*args, &block); end)
63
- class_eval definiton, file, line
64
+ ALL = %i[* all].freeze
65
+
66
+ FilterNegValue = -> (value, config) do
67
+ if value.start_with?(?-, ?^)
68
+ value = value.tr('\\-', '\\^')
69
+ flags = (config['parts'].keys + config['mount'].keys).join
70
+ [true, flags.delete(flags.delete(value))]
71
+ else
72
+ [false, value.dup]
64
73
  end
65
74
  end
66
75
 
76
+ private_constant :FilterNegValue
77
+
67
78
  # :call-seq:
68
79
  # Bootinq.require(*groups, verbose: false, &block)
69
80
  #
@@ -99,27 +110,32 @@ class Bootinq
99
110
  instance.ready!
100
111
  end
101
112
 
113
+ # Reads config from the given or default path, deserializes it and returns as a hash.
114
+ def self.deserialized_config(path: nil)
115
+ bootinq_yaml = File.read(path || ENV.fetch('BOOTINQ_PATH'))
116
+ YAML.safe_load(bootinq_yaml, [Symbol])
117
+ end
118
+
102
119
  attr_reader :flags
103
120
  attr_reader :components
104
121
 
105
- delegated :flags
106
- delegated :components
107
-
108
122
  def initialize # :no-doc:
109
- config_path = ENV.fetch('BOOTINQ_PATH')
110
- config = YAML.safe_load(File.read(config_path), [Symbol])
123
+ config = self.class.deserialized_config
111
124
  config.merge!(DEFAULT) { |_, l, r| l.nil? ? r : l }
112
125
 
113
- @_value = ENV.fetch(config['env_key']) { config['default'] }
114
- @_neg = @_value.start_with?(?-, ?^)
126
+ @_orig_value = ENV.fetch(config['env_key']) { config['default'] }
127
+ @_neg, @_value = FilterNegValue[@_orig_value, config]
128
+
129
+ @_deps = config['deps']
130
+
115
131
  @flags = []
116
132
  @components = []
117
133
 
118
- config['parts'].each { |flag, name| enable_component(name, flag: flag) }
119
- config['mount'].each { |flag, name| enable_component(name, flag: flag, as: Mountable) }
134
+ config['parts'].each { |flag, name| enable_component(name, flag: flag.to_s) }
135
+ config['mount'].each { |flag, name| enable_component(name, flag: flag.to_s, as: Mountable) }
120
136
  end
121
137
 
122
- delegated def ready? # :no-doc:
138
+ def ready? # :no-doc:
123
139
  !!@ready
124
140
  end
125
141
 
@@ -128,7 +144,7 @@ class Bootinq
128
144
  #
129
145
  # At the first call marks Bootinq as ready and returns the instance,
130
146
  # otherwise returns nil.
131
- delegated def ready!
147
+ def ready!
132
148
  return if ready?
133
149
  @ready = true
134
150
  if defined?(@_on_ready)
@@ -141,8 +157,8 @@ class Bootinq
141
157
  # :call-seq:
142
158
  # Bootinq.enable_component(name, flag: [, as: Component])
143
159
  #
144
- delegated def enable_component(name, flag:, as: Component)
145
- if @_neg ^ @_value.include?(flag)
160
+ def enable_component(name, flag:, as: Component)
161
+ if is_dependency?(name) || @_value.include?(flag)
146
162
  @flags << flag
147
163
  @components << as.new(name)
148
164
  end
@@ -153,8 +169,8 @@ class Bootinq
153
169
  #
154
170
  # Checks if a component with the given name (i.e. the same gem group)
155
171
  # is enabled
156
- delegated def enabled?(name)
157
- components.include?(name)
172
+ def enabled?(name)
173
+ ALL.include?(name) || components.include?(name)
158
174
  end
159
175
 
160
176
  # :call-seq:
@@ -162,12 +178,11 @@ class Bootinq
162
178
  # Bootinq[name] -> Bootinq::Component
163
179
  #
164
180
  # Returns a <tt>Bootinq::Component</tt> object by its name
165
- delegated def component(name)
181
+ def component(name)
166
182
  components[components.index(name)]
167
183
  end
168
184
 
169
185
  alias :[] :component
170
- delegated :[]
171
186
 
172
187
  # :call-seq:
173
188
  # Bootinq.each_mountable { |part| block } -> Array
@@ -177,7 +192,7 @@ class Bootinq
177
192
  # passing that part as a parameter. Returns the array of all mountable components.
178
193
  #
179
194
  # If no block is given, an Enumerator is returned.
180
- delegated def each_mountable(&block) # :yields: part
195
+ def each_mountable(&block) # :yields: part
181
196
  components.select(&:mountable?).each(&block)
182
197
  end
183
198
 
@@ -187,7 +202,7 @@ class Bootinq
187
202
  # Merges enabled Bootinq's groups with the given groups and, if loaded with Rails,
188
203
  # passes them to <tt>Rails.groups</tt> method, otherwise just returns the merged list
189
204
  # to use with <tt>Bundler.require</tt>.
190
- delegated def groups(*groups)
205
+ def groups(*groups)
191
206
  groups.unshift(*components.map(&:group))
192
207
  if defined?(Rails)
193
208
  Rails.groups(*groups)
@@ -219,7 +234,12 @@ class Bootinq
219
234
  # Bootinq.on all: %i(frontend backend) do
220
235
  # # do something when frontend and backend are enabled
221
236
  # end
222
- delegated def on(name = nil, any: nil, all: nil) # :yields:
237
+ def on(name = nil, any: nil, all: nil) # :yields:
238
+ if ALL.include?(name)
239
+ yield
240
+ return true
241
+ end
242
+
223
243
  if name.nil? && any.nil? && all.nil?
224
244
  raise ArgumentError, "wrong arguments (given 0, expected 1)"
225
245
  elsif (any && all) || (name && (any || all))
@@ -239,8 +259,8 @@ class Bootinq
239
259
  #
240
260
  # Takes a list of component names and yields a given block (optionally)
241
261
  # if all of them are enabled. Returns boolean matching status.
242
- delegated def on_all(*parts) # :yields:
243
- is_matched = parts.all? { |p| enabled?(p) }
262
+ def on_all(*parts) # :yields:
263
+ is_matched = parts.all? { |part| enabled?(part) }
244
264
  yield if is_matched && block_given?
245
265
  is_matched
246
266
  end
@@ -250,14 +270,14 @@ class Bootinq
250
270
  #
251
271
  # Takes a list of component names and yields a given block (optionally)
252
272
  # if any of them are enabled. Returns boolean matching status.
253
- delegated def on_any(*parts) # :yields:
254
- is_matched = parts.any? { |p| enabled?(p) }
273
+ def on_any(*parts) # :yields:
274
+ is_matched = parts.any? { |part| enabled?(part) }
255
275
  yield if is_matched && block_given?
256
276
  is_matched
257
277
  end
258
278
 
259
279
  # :call-seq:
260
- # Bottinq.switch(*parts) { block } -> nil
280
+ # Bootinq.switch(*parts) { block } -> nil
261
281
  #
262
282
  # Collector method.
263
283
  #
@@ -267,17 +287,44 @@ class Bootinq
267
287
  # part.frontend { … }
268
288
  # part.backend { … }
269
289
  # end
270
- delegated def switch # :yields: Bootinq::Switch.new
290
+ def switch # :yields: Bootinq::Switch.new
271
291
  yield(Switch.new)
272
292
  nil
273
293
  end
274
294
 
295
+ # :call-seq:
296
+ # is_dependency?(part_name) -> true or false
297
+ #
298
+ # Checks if the named component is a dependency of the enabled one.
299
+ def is_dependency?(name)
300
+ @_deps.key?(name) && @_value.count(@_deps[name]['in'].to_s) > 0
301
+ end
302
+
275
303
  # Freezes every instance variables and the instance itself.
276
304
  def freeze
277
305
  @_value.freeze
278
- @_neg.freeze
306
+ @_neg
279
307
  @flags.freeze
280
308
  @components.freeze
281
309
  super
282
310
  end
311
+
312
+ extend SingleForwardable
313
+
314
+ delegate %I[
315
+ component
316
+ components
317
+ each_mountable
318
+ enabled?
319
+ enable_component
320
+ flags
321
+ groups
322
+ on
323
+ on_all
324
+ on_any
325
+ ready!
326
+ ready?
327
+ switch
328
+ []
329
+ ] => :instance
283
330
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootinq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: '1.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-30 00:00:00.000000000 Z
11
+ date: 2022-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,7 +64,7 @@ homepage: https://github.com/estum/bootinq
64
64
  licenses:
65
65
  - MIT
66
66
  metadata: {}
67
- post_install_message:
67
+ post_install_message:
68
68
  rdoc_options: []
69
69
  require_paths:
70
70
  - lib
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubygems_version: 3.0.3
83
- signing_key:
83
+ signing_key:
84
84
  specification_version: 4
85
85
  summary: Rails Boot Inquirer
86
86
  test_files: []