bootinq 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -1
- data/bootinq.gemspec +2 -2
- data/lib/bootinq.rb +105 -41
- data/lib/bootinq/component.rb +2 -0
- data/lib/bootinq/version.rb +3 -1
- metadata +11 -13
- data/lib/tasks/bootinq_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f503e7ad103931ee10ce325a3590e3b7742f128a6947a37f59a1566ec57ceaed
|
4
|
+
data.tar.gz: 750b19a788035d9325cff83342cc67e2aac08b9ef4e892637eee07121a73b7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2878d2f0977783d2d586baa923bbc80945a2495120b522a5c198fd0c493c21f9b7ab4f591799b4f041130cfb62e3747f9287683d23db0bbccf92a64716fac49
|
7
|
+
data.tar.gz: 15eac28f64c7777dcafefb756d4a6e3644d22561c673bada3e5d6ff7187283d7596a8c62aae2e1933cab49e1f44531570a99c32e37b1db5a69e4fda4cf66eb34
|
data/Gemfile
CHANGED
data/bootinq.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "rake"
|
24
24
|
end
|
data/lib/bootinq.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "yaml"
|
2
4
|
require "singleton"
|
3
5
|
require "forwardable"
|
@@ -35,61 +37,100 @@ class Bootinq
|
|
35
37
|
}.freeze
|
36
38
|
|
37
39
|
# The helper method to bootstrap the Bootinq.
|
38
|
-
# Sets the BOOTINQ_PATH enviroment variable,
|
39
|
-
#
|
40
|
-
def self.require(*groups, verbose: false, &block) # :yields:
|
40
|
+
# Sets the BOOTINQ_PATH enviroment variable, invokes <tt>Bootinq.setup</tt> method
|
41
|
+
# with given verbose argument & block, and, finally, gets Bundler to require the given groups.
|
42
|
+
def self.require(*groups, verbose: false, &block) # :yields: Bootinq.instance
|
41
43
|
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
instance.instance_exec(&block) if block_given?
|
45
|
+
setup(verbose: verbose, &block)
|
46
46
|
|
47
47
|
Bundler.require(*instance.groups(*groups))
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
# :call-seq:
|
51
|
+
# Bootinq.setup(verbose: true, &block) -> true or false
|
52
|
+
#
|
53
|
+
# Initializes itself. When verbose: true
|
54
|
+
# Yields optional block in the own instance's binding and,
|
55
|
+
def self.setup(verbose: false, &block) # :yields: Bootinq.instance
|
56
|
+
instance
|
57
|
+
puts "Bootinq: loading components #{instance.components.join(', ')}" if verbose
|
58
|
+
instance.instance_exec(&block) if block_given?
|
59
|
+
instance
|
52
60
|
end
|
53
61
|
|
54
|
-
|
55
62
|
attr_reader :flags, :components
|
56
63
|
|
57
|
-
def initialize
|
58
|
-
|
59
|
-
|
64
|
+
def initialize # :no-doc:
|
65
|
+
config_path = ENV.fetch('BOOTINQ_PATH')
|
66
|
+
config = YAML.safe_load(File.read(config_path), [Symbol])
|
67
|
+
config.merge!(DEFAULT) { |_, l, r| l.nil? ? r : l }
|
60
68
|
|
61
69
|
@_value = ENV.fetch(config['env_key']) { config['default'] }
|
62
|
-
@_neg = @_value.start_with?(
|
70
|
+
@_neg = @_value.start_with?(?-, ?^)
|
63
71
|
@flags = []
|
64
72
|
@components = []
|
65
73
|
|
66
|
-
config['parts'].each { |flag, name| enable_component(flag
|
67
|
-
config['mount'].each { |flag, name| enable_component(flag
|
74
|
+
config['parts'].each { |flag, name| enable_component(name, flag: flag) }
|
75
|
+
config['mount'].each { |flag, name| enable_component(name, flag: flag, as: Mountable) }
|
68
76
|
end
|
69
77
|
|
70
|
-
#
|
71
|
-
|
72
|
-
|
78
|
+
# :call-seq:
|
79
|
+
# Bootinq.enable_component(name, flag: [, as: Component])
|
80
|
+
#
|
81
|
+
def enable_component(name, flag:, as: Component)
|
82
|
+
if @_neg ^ @_value.include?(flag)
|
83
|
+
@flags << flag
|
84
|
+
@components << as.new(name)
|
85
|
+
end
|
73
86
|
end
|
74
87
|
|
88
|
+
# :call-seq:
|
89
|
+
# Bootinq.enabled?(name) -> true or false
|
90
|
+
#
|
91
|
+
# Checks if a component with the given name (i.e. the same gem group)
|
92
|
+
# is enabled
|
93
|
+
def enabled?(name)
|
94
|
+
components.include?(name)
|
95
|
+
end
|
96
|
+
|
97
|
+
# :call-seq:
|
98
|
+
# Bootinq.component(name) -> Bootinq::Component
|
99
|
+
# Bootinq[name] -> Bootinq::Component
|
100
|
+
#
|
75
101
|
# Returns a <tt>Bootinq::Component</tt> object by its name
|
76
|
-
def component(
|
77
|
-
components[components.index(
|
102
|
+
def component(name)
|
103
|
+
components[components.index(name)]
|
78
104
|
end
|
79
105
|
|
80
106
|
alias :[] :component
|
81
107
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
108
|
+
|
109
|
+
# :call-seq:
|
110
|
+
# Bootinq.each_mountable { |part| block } -> Array
|
111
|
+
# Bootinq.each_mountable -> Enumerator
|
112
|
+
#
|
113
|
+
# Calls the given block once for each enabled mountable component
|
114
|
+
# passing that part as a parameter. Returns the array of all mountable components.
|
115
|
+
#
|
116
|
+
# If no block is given, an Enumerator is returned.
|
117
|
+
def each_mountable(&block) # :yields: part
|
118
|
+
components.select(&:mountable?).each(&block)
|
86
119
|
end
|
87
120
|
|
121
|
+
# :call-seq:
|
122
|
+
# Bootinq.groups(*groups)
|
123
|
+
#
|
88
124
|
# Invokes <tt>Rails.groups</tt> method within enabled Bootinq's groups
|
89
|
-
def groups(*
|
90
|
-
Rails.groups(*components.map(&:group), *
|
125
|
+
def groups(*groups)
|
126
|
+
Rails.groups(*components.map(&:group), *groups)
|
91
127
|
end
|
92
128
|
|
129
|
+
# :call-seq:
|
130
|
+
# Bootinq.on(name) { block } -> true or false
|
131
|
+
# Bootinq.on(any: [names]) { block } -> true or false
|
132
|
+
# Bootinq.on(all: [names]) { block } -> true or false
|
133
|
+
#
|
93
134
|
# Takes a component's name or single-key options hash as an argument and
|
94
135
|
# yields a given block if the target components are enabled.
|
95
136
|
#
|
@@ -109,20 +150,44 @@ class Bootinq
|
|
109
150
|
# # do something when frontend and backend are enabled
|
110
151
|
# end
|
111
152
|
def on(name = nil, any: nil, all: nil) # :yields:
|
112
|
-
if
|
113
|
-
raise ArgumentError, "expected single argument or one of keywords: `all' or `any'"
|
114
|
-
elsif name
|
115
|
-
yield if enabled?(name)
|
116
|
-
elsif any
|
117
|
-
yield if any.any? { |part| enabled?(part) }
|
118
|
-
elsif all
|
119
|
-
yield if all.all? { |part| enabled?(part) }
|
120
|
-
else
|
153
|
+
if name.nil? && any.nil? && all.nil?
|
121
154
|
raise ArgumentError, "wrong arguments (given 0, expected 1)"
|
155
|
+
elsif (any && all) || (name && (any || all))
|
156
|
+
raise ArgumentError, "expected single argument or one of keywords: `all' or `any'"
|
122
157
|
end
|
158
|
+
|
159
|
+
is_matched =
|
160
|
+
name ? enabled?(name) :
|
161
|
+
any ? on_any(*any) :
|
162
|
+
all ? on_all(*all) : false
|
163
|
+
yield if is_matched
|
164
|
+
is_matched
|
165
|
+
end
|
166
|
+
|
167
|
+
# :call-seq:
|
168
|
+
# Bootinq.on_all(*names) { block } -> true or false
|
169
|
+
#
|
170
|
+
# Takes a list of component names and yields a given block (optionally)
|
171
|
+
# if all of them are enabled. Returns boolean matching status.
|
172
|
+
def on_all(*parts) # :yields:
|
173
|
+
is_matched = parts.all? { |p| enabled?(p) }
|
174
|
+
yield if is_matched && block_given?
|
175
|
+
is_matched
|
123
176
|
end
|
124
177
|
|
125
|
-
|
178
|
+
# :call-seq:
|
179
|
+
# Bootinq.on_all(*names) { block } -> true or false
|
180
|
+
#
|
181
|
+
# Takes a list of component names and yields a given block (optionally)
|
182
|
+
# if any of them are enabled. Returns boolean matching status.
|
183
|
+
def on_any(*parts) # :yields:
|
184
|
+
is_matched = parts.any? { |p| enabled?(p) }
|
185
|
+
yield if is_matched && block_given?
|
186
|
+
is_matched
|
187
|
+
end
|
188
|
+
|
189
|
+
# Freezes every instance variables and the instance itself.
|
190
|
+
def freeze
|
126
191
|
@_value.freeze
|
127
192
|
@_neg.freeze
|
128
193
|
@flags.freeze
|
@@ -132,10 +197,9 @@ class Bootinq
|
|
132
197
|
|
133
198
|
def_delegators "instance", *instance_methods(false)
|
134
199
|
|
135
|
-
|
136
|
-
|
137
|
-
@flags << flag
|
138
|
-
@components << yield
|
139
|
-
end
|
200
|
+
def self.new # :no-doc:
|
201
|
+
super.freeze
|
140
202
|
end
|
203
|
+
|
204
|
+
private_class_method :new
|
141
205
|
end
|
data/lib/bootinq/component.rb
CHANGED
data/lib/bootinq/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootinq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
description: Allows to select which bundle groups to boot in the current rails process
|
42
42
|
email:
|
43
43
|
- anton.estum@gmail.com
|
@@ -59,7 +59,6 @@ files:
|
|
59
59
|
- lib/bootinq.yml
|
60
60
|
- lib/bootinq/component.rb
|
61
61
|
- lib/bootinq/version.rb
|
62
|
-
- lib/tasks/bootinq_tasks.rake
|
63
62
|
homepage: https://github.com/estum/bootinq
|
64
63
|
licenses:
|
65
64
|
- MIT
|
@@ -80,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
79
|
version: '0'
|
81
80
|
requirements: []
|
82
81
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.7.6
|
84
83
|
signing_key:
|
85
84
|
specification_version: 4
|
86
85
|
summary: Rails Boot Inquirer
|
87
86
|
test_files: []
|
88
|
-
has_rdoc:
|