bootinq 1.3.0 → 1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/lib/bootinq.rb +79 -30
- data/lib/bootinq/switch.rb +6 -22
- data/lib/bootinq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1e1d6c92b8790ff798d3ac3af73aa4d1ba51d65e5d30a710e71b109dff4a1d2
|
4
|
+
data.tar.gz: ff41e0be38f693a836592446d3a8600613497595228075a325bfa3cd06a36585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d003846a5991fef4e37aaf9ab72c03878eaaecb98b0b347b8ac537f4d583a880b578bda284ec1d1539396b3a822a0d72511cf349d54cb6638892052768a563
|
7
|
+
data.tar.gz: 28a35e3389f226c94126dc11adcecbdde73cb6b8b9b02876ffb987cddaec8f0d32274e3831d61ba163c64bde0eebe00c505bb0b24c7aa3032e445e840fb350dd
|
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/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:
|
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,9 +57,22 @@ class Bootinq
|
|
52
57
|
"env_key" => 'BOOTINQ',
|
53
58
|
"default" => '',
|
54
59
|
"parts" => {},
|
55
|
-
"mount" => {}
|
60
|
+
"mount" => {},
|
61
|
+
"deps" => {}
|
56
62
|
}.freeze
|
57
63
|
|
64
|
+
FilterNegValue = -> (value, config) do
|
65
|
+
if value.start_with?(?-, ?^)
|
66
|
+
value = value.tr('\\-', '\\^')
|
67
|
+
flags = (config['parts'].keys + config['mount'].keys).join
|
68
|
+
[true, flags.delete(flags.delete(value))]
|
69
|
+
else
|
70
|
+
[false, value.dup]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private_constant :FilterNegValue
|
75
|
+
|
58
76
|
class << self
|
59
77
|
protected def delegated(sym) # :no-doc:
|
60
78
|
location = caller_locations(1, 1).first
|
@@ -67,28 +85,36 @@ class Bootinq
|
|
67
85
|
# :call-seq:
|
68
86
|
# Bootinq.require(*groups, verbose: false, &block)
|
69
87
|
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# invokes the <tt>Bootinq.setup</tt> method with the given verbose key argument & block,
|
73
|
-
# and, finally, gets Bundler to require the given groups.
|
88
|
+
# Invokes the <tt>Bootinq.init</tt> method with the given verbose key argument & block,
|
89
|
+
# and, finally, makes Bundler to require the given groups.
|
74
90
|
def self.require(*groups, verbose: false, &block) # :yields: Bootinq.instance
|
75
|
-
|
76
|
-
|
77
|
-
setup(verbose: verbose, &block)
|
78
|
-
|
91
|
+
init(verbose: verbose, &block)
|
79
92
|
Bundler.require(*instance.groups(*groups))
|
80
93
|
end
|
81
94
|
|
82
95
|
# :call-seq:
|
83
|
-
# Bootinq.setup(verbose: false, &block)
|
96
|
+
# Bootinq.setup(*groups, verbose: false, &block)
|
97
|
+
#
|
98
|
+
# Invokes the <tt>Bootinq.init</tt> method with the given verbose key argument & block,
|
99
|
+
# and, finally, makes Bundler to setup the given groups.
|
100
|
+
def self.setup(*groups, verbose: false, &block) # :yields: Bootinq.instance
|
101
|
+
init(verbose: verbose, &block)
|
102
|
+
Bundler.setup(*instance.groups(*groups))
|
103
|
+
end
|
104
|
+
|
105
|
+
# :call-seq:
|
106
|
+
# Bootinq.init(verbose: false, &block) -> true or false
|
84
107
|
#
|
85
|
-
# Initializes itself.
|
108
|
+
# Initializes itself. Sets the BOOTINQ_PATH enviroment variable if it is missing.
|
109
|
+
# To track inquired components use <tt>verbose: true</tt> key argument.
|
86
110
|
# Optionally yields block within the own instance's binding.
|
87
|
-
def self.
|
111
|
+
def self.init(verbose: false, &block) # :yields: Bootinq.instance
|
112
|
+
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(2, 1)[0].path)
|
113
|
+
|
88
114
|
instance
|
115
|
+
instance.instance_variable_set(:@_on_ready, block.to_proc) if block_given?
|
89
116
|
puts "Bootinq: loading components #{instance.components.join(', ')}" if verbose
|
90
|
-
instance.
|
91
|
-
instance
|
117
|
+
instance.ready!
|
92
118
|
end
|
93
119
|
|
94
120
|
attr_reader :flags
|
@@ -102,21 +128,42 @@ class Bootinq
|
|
102
128
|
config = YAML.safe_load(File.read(config_path), [Symbol])
|
103
129
|
config.merge!(DEFAULT) { |_, l, r| l.nil? ? r : l }
|
104
130
|
|
105
|
-
@
|
106
|
-
@_neg
|
131
|
+
@_orig_value = ENV.fetch(config['env_key']) { config['default'] }
|
132
|
+
@_neg, @_value = FilterNegValue[@_orig_value, config]
|
133
|
+
|
134
|
+
@_deps = config['deps']
|
135
|
+
|
107
136
|
@flags = []
|
108
137
|
@components = []
|
109
|
-
@switch = Switch.new(*@components)
|
110
138
|
|
111
|
-
config['parts'].each { |flag, name| enable_component(name, flag: flag) }
|
112
|
-
config['mount'].each { |flag, name| enable_component(name, flag: flag, as: Mountable) }
|
139
|
+
config['parts'].each { |flag, name| enable_component(name, flag: flag.to_s) }
|
140
|
+
config['mount'].each { |flag, name| enable_component(name, flag: flag.to_s, as: Mountable) }
|
141
|
+
end
|
142
|
+
|
143
|
+
delegated def ready? # :no-doc:
|
144
|
+
!!@ready
|
145
|
+
end
|
146
|
+
|
147
|
+
# :call-seq:
|
148
|
+
# Bootinq.ready! -> nil or self
|
149
|
+
#
|
150
|
+
# At the first call marks Bootinq as ready and returns the instance,
|
151
|
+
# otherwise returns nil.
|
152
|
+
delegated def ready!
|
153
|
+
return if ready?
|
154
|
+
@ready = true
|
155
|
+
if defined?(@_on_ready)
|
156
|
+
instance_exec(&@_on_ready)
|
157
|
+
remove_instance_variable :@_on_ready
|
158
|
+
end
|
159
|
+
freeze
|
113
160
|
end
|
114
161
|
|
115
162
|
# :call-seq:
|
116
163
|
# Bootinq.enable_component(name, flag: [, as: Component])
|
117
164
|
#
|
118
165
|
delegated def enable_component(name, flag:, as: Component)
|
119
|
-
if
|
166
|
+
if is_dependency?(name) || @_value.include?(flag)
|
120
167
|
@flags << flag
|
121
168
|
@components << as.new(name)
|
122
169
|
end
|
@@ -231,7 +278,7 @@ class Bootinq
|
|
231
278
|
end
|
232
279
|
|
233
280
|
# :call-seq:
|
234
|
-
#
|
281
|
+
# Bootinq.switch(*parts) { block } -> nil
|
235
282
|
#
|
236
283
|
# Collector method.
|
237
284
|
#
|
@@ -242,22 +289,24 @@ class Bootinq
|
|
242
289
|
# part.backend { … }
|
243
290
|
# end
|
244
291
|
delegated def switch # :yields: Bootinq::Switch.new
|
245
|
-
yield(
|
292
|
+
yield(Switch.new)
|
246
293
|
nil
|
247
294
|
end
|
248
295
|
|
296
|
+
# :call-seq:
|
297
|
+
# is_dependency?(part_name) -> true or false
|
298
|
+
#
|
299
|
+
# Checks if the named component is a dependency of the enabled one.
|
300
|
+
def is_dependency?(name)
|
301
|
+
@_deps.key?(name) && @_value.count(@_deps[name]['in'].to_s) > 0
|
302
|
+
end
|
303
|
+
|
249
304
|
# Freezes every instance variables and the instance itself.
|
250
305
|
def freeze
|
251
306
|
@_value.freeze
|
252
|
-
@_neg
|
307
|
+
@_neg
|
253
308
|
@flags.freeze
|
254
309
|
@components.freeze
|
255
310
|
super
|
256
311
|
end
|
257
|
-
|
258
|
-
def self.new
|
259
|
-
super.freeze
|
260
|
-
end
|
261
|
-
|
262
|
-
private_class_method :new
|
263
312
|
end
|
data/lib/bootinq/switch.rb
CHANGED
@@ -5,32 +5,16 @@ class Bootinq
|
|
5
5
|
undef_method :==
|
6
6
|
undef_method :equal?
|
7
7
|
|
8
|
-
module YieldMixin
|
9
|
-
def yield_block
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
private_constant :YieldMixin
|
15
|
-
|
16
|
-
def self.new(*names)
|
17
|
-
switch = super()
|
18
|
-
mixin = ::Module.new
|
19
|
-
mixin.include(YieldMixin)
|
20
|
-
names.each { |name| mixin.alias_method name, :yield_block }
|
21
|
-
mixin.send(:private, :yield_block)
|
22
|
-
mixin.send(:extend_object, switch)
|
23
|
-
switch
|
24
|
-
ensure
|
25
|
-
mixin = nil
|
26
|
-
end
|
27
|
-
|
28
8
|
def raise(*args) # :no-doc:
|
29
9
|
::Object.send(:raise, *args)
|
30
10
|
end
|
31
11
|
|
32
|
-
def method_missing(*)
|
33
|
-
|
12
|
+
def method_missing(name, *)
|
13
|
+
if ::Bootinq.enabled?(name)
|
14
|
+
yield()
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
34
18
|
end
|
35
19
|
end
|
36
20
|
end
|
data/lib/bootinq/version.rb
CHANGED
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
|
+
version: '1.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|