bootinq 1.1.0 → 1.2.0
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 +4 -4
- data/README.md +24 -5
- data/lib/bootinq.rb +61 -21
- data/lib/bootinq/component.rb +41 -12
- 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: 266e204b1e16ba81aaaf17e2ab6b638f2c33b1717a9c728e65332b6b2274e98d
|
4
|
+
data.tar.gz: 0f8210ddf0aae40d21ccc68b3964df30b7102ea35cb76c04779e3a2f48d0f9dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d3172c9a7a38e335585b0b1a35dc7bdaccbb993076095cd414a317f891d0506e6b0995b5e7eb4cdea9f885553658cd175219273a788db797994d63eca59a44
|
7
|
+
data.tar.gz: 182655c54c91a0a4cac2d7c17e5750e59e8941309a9ce492faddc1204f30e72a90c847f5e48e23ffb549cc9dc60ad4ed0c0b064eb92348960a6b85286380321b
|
data/README.md
CHANGED
@@ -15,9 +15,9 @@ And then execute:
|
|
15
15
|
$ bundle
|
16
16
|
|
17
17
|
|
18
|
-
##
|
18
|
+
## Get started
|
19
19
|
|
20
|
-
There are few steps to setup partial gem booting in
|
20
|
+
There are few steps to setup partial gem booting using Bootinq in any ruby application:
|
21
21
|
|
22
22
|
### 1. Declare loadable parts
|
23
23
|
|
@@ -60,7 +60,9 @@ group :console_boot do
|
|
60
60
|
end
|
61
61
|
```
|
62
62
|
|
63
|
-
|
63
|
+
## Ruby on Rails
|
64
|
+
|
65
|
+
### 3. Swap Bundle.require to Bootinq.require
|
64
66
|
|
65
67
|
Insert `require "bootinq"` to the top of `config/application.rb` file and replace `Bundler.require(*Rails.groups)` with the `Bootinq.require`:
|
66
68
|
|
@@ -74,11 +76,10 @@ require 'rails/all'
|
|
74
76
|
require 'bootinq'
|
75
77
|
|
76
78
|
# With no additional gem groups:
|
77
|
-
Bootinq.require
|
79
|
+
Bootinq.require(verbose: true)
|
78
80
|
# otherwise, set them like in <tt>Bundle.require(*Rails.groups(*groups))</tt>:
|
79
81
|
# Bootinq.require(:assets => %w(development test))
|
80
82
|
|
81
|
-
puts "* Bootinq: loading components #{Bootinq.components * ', '}"
|
82
83
|
```
|
83
84
|
|
84
85
|
#### Separate load rails components with Bootinq
|
@@ -131,6 +132,24 @@ api: env BOOTINQ=a MAX_THREADS=128 bundle exec puma -w 4
|
|
131
132
|
admin: env BOOTINQ=z bundle exec puma
|
132
133
|
```
|
133
134
|
|
135
|
+
## Usage with other frameworks
|
136
|
+
|
137
|
+
3. Locate `Bundler.require(...)` in your app and insert `require "bootinq"` above it.
|
138
|
+
|
139
|
+
4. Replace located `Bundler.require(...)` line with the `Bootinq.require(...)`.
|
140
|
+
|
141
|
+
For example, if you are using Grape:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
# config/application.rb
|
145
|
+
|
146
|
+
require 'boot'
|
147
|
+
require 'bootinq'
|
148
|
+
|
149
|
+
# Bundler.require :default, ENV['RACK_ENV']
|
150
|
+
Bootinq.require :default, ENV['RACK_ENV'], verbose: true
|
151
|
+
|
152
|
+
|
134
153
|
## Development
|
135
154
|
|
136
155
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/bootinq.rb
CHANGED
@@ -9,11 +9,30 @@ require "bootinq/component"
|
|
9
9
|
#
|
10
10
|
# == Installation
|
11
11
|
#
|
12
|
+
# === Ruby on Rails
|
13
|
+
#
|
12
14
|
# 1. Insert <tt>require "bootinq"</tt> in the top of <tt>config/application.rb</tt>
|
13
15
|
#
|
14
16
|
# 2. Find <tt>Bundler.require(*Rails.groups)</tt> line below and replace it
|
15
17
|
# with the <tt>Bootinq.require</tt>.
|
16
18
|
#
|
19
|
+
# === Other
|
20
|
+
#
|
21
|
+
# 1. Locate <tt>Bundler.require(...)</tt> in your app and insert <tt>require "bootinq"</tt> above.
|
22
|
+
#
|
23
|
+
# 2. Replace located <tt>Bundler.require(...)</tt> line with the <tt>Bootinq.require(...)</tt>.
|
24
|
+
#
|
25
|
+
# For example, if you are using Grape:
|
26
|
+
#
|
27
|
+
# # config/application.rb
|
28
|
+
#
|
29
|
+
# require 'boot'
|
30
|
+
# require 'bootinq'
|
31
|
+
#
|
32
|
+
# # Bundler.require :default, ENV['RACK_ENV']
|
33
|
+
# Bootinq.require :default, ENV['RACK_ENV'], verbose: true
|
34
|
+
# ...
|
35
|
+
#
|
17
36
|
# == Example <tt>config/bootinq.yml</tt>:
|
18
37
|
#
|
19
38
|
# env_key: BOOTINQ
|
@@ -26,7 +45,6 @@ require "bootinq/component"
|
|
26
45
|
# a: :api
|
27
46
|
# f: :engine
|
28
47
|
class Bootinq
|
29
|
-
extend SingleForwardable
|
30
48
|
include Singleton
|
31
49
|
|
32
50
|
DEFAULT = {
|
@@ -36,9 +54,22 @@ class Bootinq
|
|
36
54
|
"mount" => {}
|
37
55
|
}.freeze
|
38
56
|
|
57
|
+
class << self
|
58
|
+
protected def delegated(sym) # :no-doc:
|
59
|
+
location = caller_locations(1, 1).first
|
60
|
+
file, line = location.path, location.lineno
|
61
|
+
definiton = %(def self.#{sym}(*args, &block); instance.#{sym}(*args, &block); end)
|
62
|
+
class_eval definiton, file, line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# :call-seq:
|
67
|
+
# Bootinq.require(*groups, verbose: false, &block)
|
68
|
+
#
|
39
69
|
# The helper method to bootstrap the Bootinq.
|
40
|
-
# Sets the BOOTINQ_PATH enviroment variable
|
41
|
-
# with given verbose argument & block,
|
70
|
+
# Sets the BOOTINQ_PATH enviroment variable if it is missing,
|
71
|
+
# invokes the <tt>Bootinq.setup</tt> method with the given verbose key argument & block,
|
72
|
+
# and, finally, gets Bundler to require the given groups.
|
42
73
|
def self.require(*groups, verbose: false, &block) # :yields: Bootinq.instance
|
43
74
|
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
|
44
75
|
|
@@ -48,10 +79,10 @@ class Bootinq
|
|
48
79
|
end
|
49
80
|
|
50
81
|
# :call-seq:
|
51
|
-
# Bootinq.setup(verbose:
|
82
|
+
# Bootinq.setup(verbose: false, &block) -> true or false
|
52
83
|
#
|
53
|
-
# Initializes itself.
|
54
|
-
#
|
84
|
+
# Initializes itself. To track inquired components use <tt>verbose: true</tt> key argument.
|
85
|
+
# Optionally yields block within the own instance's binding.
|
55
86
|
def self.setup(verbose: false, &block) # :yields: Bootinq.instance
|
56
87
|
instance
|
57
88
|
puts "Bootinq: loading components #{instance.components.join(', ')}" if verbose
|
@@ -59,7 +90,11 @@ class Bootinq
|
|
59
90
|
instance
|
60
91
|
end
|
61
92
|
|
62
|
-
attr_reader :flags
|
93
|
+
attr_reader :flags
|
94
|
+
attr_reader :components
|
95
|
+
|
96
|
+
delegated :flags
|
97
|
+
delegated :components
|
63
98
|
|
64
99
|
def initialize # :no-doc:
|
65
100
|
config_path = ENV.fetch('BOOTINQ_PATH')
|
@@ -78,7 +113,7 @@ class Bootinq
|
|
78
113
|
# :call-seq:
|
79
114
|
# Bootinq.enable_component(name, flag: [, as: Component])
|
80
115
|
#
|
81
|
-
def enable_component(name, flag:, as: Component)
|
116
|
+
delegated def enable_component(name, flag:, as: Component)
|
82
117
|
if @_neg ^ @_value.include?(flag)
|
83
118
|
@flags << flag
|
84
119
|
@components << as.new(name)
|
@@ -90,7 +125,7 @@ class Bootinq
|
|
90
125
|
#
|
91
126
|
# Checks if a component with the given name (i.e. the same gem group)
|
92
127
|
# is enabled
|
93
|
-
def enabled?(name)
|
128
|
+
delegated def enabled?(name)
|
94
129
|
components.include?(name)
|
95
130
|
end
|
96
131
|
|
@@ -99,12 +134,12 @@ class Bootinq
|
|
99
134
|
# Bootinq[name] -> Bootinq::Component
|
100
135
|
#
|
101
136
|
# Returns a <tt>Bootinq::Component</tt> object by its name
|
102
|
-
def component(name)
|
137
|
+
delegated def component(name)
|
103
138
|
components[components.index(name)]
|
104
139
|
end
|
105
140
|
|
106
141
|
alias :[] :component
|
107
|
-
|
142
|
+
delegated :[]
|
108
143
|
|
109
144
|
# :call-seq:
|
110
145
|
# Bootinq.each_mountable { |part| block } -> Array
|
@@ -114,16 +149,23 @@ class Bootinq
|
|
114
149
|
# passing that part as a parameter. Returns the array of all mountable components.
|
115
150
|
#
|
116
151
|
# If no block is given, an Enumerator is returned.
|
117
|
-
def each_mountable(&block) # :yields: part
|
152
|
+
delegated def each_mountable(&block) # :yields: part
|
118
153
|
components.select(&:mountable?).each(&block)
|
119
154
|
end
|
120
155
|
|
121
156
|
# :call-seq:
|
122
157
|
# Bootinq.groups(*groups)
|
123
158
|
#
|
124
|
-
#
|
125
|
-
|
126
|
-
|
159
|
+
# Merges enabled Bootinq's groups with the given groups and, if loaded with Rails,
|
160
|
+
# passes them to <tt>Rails.groups</tt> method, otherwise just returns the merged list
|
161
|
+
# to use with <tt>Bundler.require</tt>.
|
162
|
+
delegated def groups(*groups)
|
163
|
+
groups.unshift(*components.map(&:group))
|
164
|
+
if defined?(Rails)
|
165
|
+
Rails.groups(*groups)
|
166
|
+
else
|
167
|
+
groups
|
168
|
+
end
|
127
169
|
end
|
128
170
|
|
129
171
|
# :call-seq:
|
@@ -149,7 +191,7 @@ class Bootinq
|
|
149
191
|
# Bootinq.on all: %i(frontend backend) do
|
150
192
|
# # do something when frontend and backend are enabled
|
151
193
|
# end
|
152
|
-
def on(name = nil, any: nil, all: nil) # :yields:
|
194
|
+
delegated def on(name = nil, any: nil, all: nil) # :yields:
|
153
195
|
if name.nil? && any.nil? && all.nil?
|
154
196
|
raise ArgumentError, "wrong arguments (given 0, expected 1)"
|
155
197
|
elsif (any && all) || (name && (any || all))
|
@@ -169,7 +211,7 @@ class Bootinq
|
|
169
211
|
#
|
170
212
|
# Takes a list of component names and yields a given block (optionally)
|
171
213
|
# if all of them are enabled. Returns boolean matching status.
|
172
|
-
def on_all(*parts) # :yields:
|
214
|
+
delegated def on_all(*parts) # :yields:
|
173
215
|
is_matched = parts.all? { |p| enabled?(p) }
|
174
216
|
yield if is_matched && block_given?
|
175
217
|
is_matched
|
@@ -180,7 +222,7 @@ class Bootinq
|
|
180
222
|
#
|
181
223
|
# Takes a list of component names and yields a given block (optionally)
|
182
224
|
# if any of them are enabled. Returns boolean matching status.
|
183
|
-
def on_any(*parts) # :yields:
|
225
|
+
delegated def on_any(*parts) # :yields:
|
184
226
|
is_matched = parts.any? { |p| enabled?(p) }
|
185
227
|
yield if is_matched && block_given?
|
186
228
|
is_matched
|
@@ -195,9 +237,7 @@ class Bootinq
|
|
195
237
|
super
|
196
238
|
end
|
197
239
|
|
198
|
-
|
199
|
-
|
200
|
-
def self.new # :no-doc:
|
240
|
+
def self.new
|
201
241
|
super.freeze
|
202
242
|
end
|
203
243
|
|
data/lib/bootinq/component.rb
CHANGED
@@ -20,6 +20,17 @@ class Bootinq
|
|
20
20
|
false
|
21
21
|
end
|
22
22
|
|
23
|
+
def module_name
|
24
|
+
@id2name.camelcase.to_sym
|
25
|
+
end
|
26
|
+
|
27
|
+
def engine
|
28
|
+
end
|
29
|
+
|
30
|
+
def kind_of?(klass)
|
31
|
+
super || @intern.kind_of?(klass)
|
32
|
+
end
|
33
|
+
|
23
34
|
def == other
|
24
35
|
case other
|
25
36
|
when String then other == @id2name
|
@@ -28,26 +39,44 @@ class Bootinq
|
|
28
39
|
end
|
29
40
|
end
|
30
41
|
|
31
|
-
def
|
32
|
-
|
42
|
+
def ===(other)
|
43
|
+
case other
|
44
|
+
when String then other === @id2name
|
45
|
+
when Symbol then other === @intern
|
46
|
+
else super
|
47
|
+
end
|
33
48
|
end
|
34
49
|
|
35
|
-
def
|
50
|
+
def casecmp(other)
|
51
|
+
case other
|
52
|
+
when String then @id2name.casecmp(other)
|
53
|
+
when Symbol then @intern.casecmp(other)
|
54
|
+
when self.class then casecmp(other.to_s)
|
55
|
+
end
|
36
56
|
end
|
37
57
|
|
38
|
-
def
|
39
|
-
|
58
|
+
def casecmp?(other)
|
59
|
+
case other
|
60
|
+
when String then @id2name.casecmp?(other)
|
61
|
+
when Symbol then @intern.casecmp?(other)
|
62
|
+
when self.class then casecmp?(other.to_s)
|
63
|
+
end
|
40
64
|
end
|
41
65
|
|
42
|
-
|
43
|
-
@intern
|
44
|
-
end
|
66
|
+
%i(inspect to_proc __id__ hash).
|
67
|
+
each { |sym| class_eval %(def #{sym}; @intern.#{sym}; end), __FILE__, __LINE__ + 1 }
|
45
68
|
|
46
|
-
|
69
|
+
%i(encoding empty? length).
|
70
|
+
each { |sym| class_eval %(def #{sym}; @id2name.#{sym}; end), __FILE__, __LINE__ + 1 }
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
72
|
+
%i(match match? =~ []).
|
73
|
+
each { |sym| class_eval %(def #{sym}(*args); @id2name.#{sym}(*args); end), __FILE__, __LINE__ + 1 }
|
74
|
+
|
75
|
+
%i(upcase downcase capitalize swapcase succ next).
|
76
|
+
each { |sym| class_eval %(def #{sym}; self.class.new(@intern.#{sym}); end), __FILE__, __LINE__ + 1 }
|
77
|
+
|
78
|
+
alias :slice :[]
|
79
|
+
alias :size :length
|
51
80
|
end
|
52
81
|
|
53
82
|
class Mountable < Component
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|