bootinq 1.1.0 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f503e7ad103931ee10ce325a3590e3b7742f128a6947a37f59a1566ec57ceaed
4
- data.tar.gz: 750b19a788035d9325cff83342cc67e2aac08b9ef4e892637eee07121a73b7b4
3
+ metadata.gz: 24d33e5b4116c1406447099627f69b28099408be01a35b8addb8870c70b1d526
4
+ data.tar.gz: ab43719f9bb45caadff14a577a23449157e1fa24e35301301a59d903947bb199
5
5
  SHA512:
6
- metadata.gz: f2878d2f0977783d2d586baa923bbc80945a2495120b522a5c198fd0c493c21f9b7ab4f591799b4f041130cfb62e3747f9287683d23db0bbccf92a64716fac49
7
- data.tar.gz: 15eac28f64c7777dcafefb756d4a6e3644d22561c673bada3e5d6ff7187283d7596a8c62aae2e1933cab49e1f44531570a99c32e37b1db5a69e4fda4cf66eb34
6
+ metadata.gz: 1a145181cdbd31411d4b6208cf84a418adb74ea1594d9d76fe10aab41af3e1e52a3bd97be211ef4e946d2f5285a6462ed3fd058d5d139cd8f95216fd3644c052
7
+ data.tar.gz: 8ec205d218a4a262b8c45070b3e0141d0e5b13c97b2749a79f48def1a4836625b0615c672e9de992d1c8cba16965e5b90490672bb396ffbfc99bc65e85d2f97e
data/README.md CHANGED
@@ -15,9 +15,9 @@ And then execute:
15
15
  $ bundle
16
16
 
17
17
 
18
- ## Usage
18
+ ## Get started
19
19
 
20
- There are few steps to setup partial gem booting in a Rails application using Bootinq:
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
- ### 3. Change config/application.rb
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.
@@ -4,16 +4,36 @@ require "yaml"
4
4
  require "singleton"
5
5
  require "forwardable"
6
6
  require "bootinq/component"
7
+ require "bootinq/switch"
7
8
 
8
9
  # = Bootinq
9
10
  #
10
11
  # == Installation
11
12
  #
13
+ # === Ruby on Rails
14
+ #
12
15
  # 1. Insert <tt>require "bootinq"</tt> in the top of <tt>config/application.rb</tt>
13
16
  #
14
17
  # 2. Find <tt>Bundler.require(*Rails.groups)</tt> line below and replace it
15
18
  # with the <tt>Bootinq.require</tt>.
16
19
  #
20
+ # === Other
21
+ #
22
+ # 1. Locate <tt>Bundler.require(...)</tt> in your app and insert <tt>require "bootinq"</tt> above.
23
+ #
24
+ # 2. Replace located <tt>Bundler.require(...)</tt> line with the <tt>Bootinq.require(...)</tt>.
25
+ #
26
+ # For example, if you are using Grape:
27
+ #
28
+ # # config/application.rb
29
+ #
30
+ # require 'boot'
31
+ # require 'bootinq'
32
+ #
33
+ # # Bundler.require :default, ENV['RACK_ENV']
34
+ # Bootinq.require :default, ENV['RACK_ENV'], verbose: true
35
+ # ...
36
+ #
17
37
  # == Example <tt>config/bootinq.yml</tt>:
18
38
  #
19
39
  # env_key: BOOTINQ
@@ -26,7 +46,6 @@ require "bootinq/component"
26
46
  # a: :api
27
47
  # f: :engine
28
48
  class Bootinq
29
- extend SingleForwardable
30
49
  include Singleton
31
50
 
32
51
  DEFAULT = {
@@ -36,30 +55,55 @@ class Bootinq
36
55
  "mount" => {}
37
56
  }.freeze
38
57
 
39
- # The helper method to bootstrap the Bootinq.
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
43
- ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
44
-
45
- setup(verbose: verbose, &block)
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
+ end
65
+ end
46
66
 
67
+ # :call-seq:
68
+ # Bootinq.require(*groups, verbose: false, &block)
69
+ #
70
+ # Invokes the <tt>Bootinq.init</tt> method with the given verbose key argument & block,
71
+ # and, finally, makes Bundler to require the given groups.
72
+ def self.require(*groups, verbose: false, &block) # :yields: Bootinq.instance
73
+ init(verbose: verbose, &block)
47
74
  Bundler.require(*instance.groups(*groups))
48
75
  end
49
76
 
50
77
  # :call-seq:
51
- # Bootinq.setup(verbose: true, &block) -> true or false
78
+ # Bootinq.setup(*groups, verbose: false, &block)
52
79
  #
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
80
+ # Invokes the <tt>Bootinq.init</tt> method with the given verbose key argument & block,
81
+ # and, finally, makes Bundler to setup the given groups.
82
+ def self.setup(*groups, verbose: false, &block) # :yields: Bootinq.instance
83
+ init(verbose: verbose, &block)
84
+ Bundler.setup(*instance.groups(*groups))
85
+ end
86
+
87
+ # :call-seq:
88
+ # Bootinq.init(verbose: false, &block) -> true or false
89
+ #
90
+ # Initializes itself. Sets the BOOTINQ_PATH enviroment variable if it is missing.
91
+ # To track inquired components use <tt>verbose: true</tt> key argument.
92
+ # Optionally yields block within the own instance's binding.
93
+ def self.init(verbose: false, &block) # :yields: Bootinq.instance
94
+ ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(2, 1)[0].path)
95
+
56
96
  instance
97
+ instance.instance_variable_set(:@_on_ready, block.to_proc) if block_given?
57
98
  puts "Bootinq: loading components #{instance.components.join(', ')}" if verbose
58
- instance.instance_exec(&block) if block_given?
59
- instance
99
+ instance.ready!
60
100
  end
61
101
 
62
- attr_reader :flags, :components
102
+ attr_reader :flags
103
+ attr_reader :components
104
+
105
+ delegated :flags
106
+ delegated :components
63
107
 
64
108
  def initialize # :no-doc:
65
109
  config_path = ENV.fetch('BOOTINQ_PATH')
@@ -75,10 +119,29 @@ class Bootinq
75
119
  config['mount'].each { |flag, name| enable_component(name, flag: flag, as: Mountable) }
76
120
  end
77
121
 
122
+ delegated def ready? # :no-doc:
123
+ !!@ready
124
+ end
125
+
126
+ # :call-seq:
127
+ # Bootinq.ready! -> nil or self
128
+ #
129
+ # At the first call marks Bootinq as ready and returns the instance,
130
+ # otherwise returns nil.
131
+ delegated def ready!
132
+ return if ready?
133
+ @ready = true
134
+ if defined?(@_on_ready)
135
+ instance_exec(&@_on_ready)
136
+ remove_instance_variable :@_on_ready
137
+ end
138
+ self
139
+ end
140
+
78
141
  # :call-seq:
79
142
  # Bootinq.enable_component(name, flag: [, as: Component])
80
143
  #
81
- def enable_component(name, flag:, as: Component)
144
+ delegated def enable_component(name, flag:, as: Component)
82
145
  if @_neg ^ @_value.include?(flag)
83
146
  @flags << flag
84
147
  @components << as.new(name)
@@ -90,7 +153,7 @@ class Bootinq
90
153
  #
91
154
  # Checks if a component with the given name (i.e. the same gem group)
92
155
  # is enabled
93
- def enabled?(name)
156
+ delegated def enabled?(name)
94
157
  components.include?(name)
95
158
  end
96
159
 
@@ -99,12 +162,12 @@ class Bootinq
99
162
  # Bootinq[name] -> Bootinq::Component
100
163
  #
101
164
  # Returns a <tt>Bootinq::Component</tt> object by its name
102
- def component(name)
165
+ delegated def component(name)
103
166
  components[components.index(name)]
104
167
  end
105
168
 
106
169
  alias :[] :component
107
-
170
+ delegated :[]
108
171
 
109
172
  # :call-seq:
110
173
  # Bootinq.each_mountable { |part| block } -> Array
@@ -114,16 +177,23 @@ class Bootinq
114
177
  # passing that part as a parameter. Returns the array of all mountable components.
115
178
  #
116
179
  # If no block is given, an Enumerator is returned.
117
- def each_mountable(&block) # :yields: part
180
+ delegated def each_mountable(&block) # :yields: part
118
181
  components.select(&:mountable?).each(&block)
119
182
  end
120
183
 
121
184
  # :call-seq:
122
185
  # Bootinq.groups(*groups)
123
186
  #
124
- # Invokes <tt>Rails.groups</tt> method within enabled Bootinq's groups
125
- def groups(*groups)
126
- Rails.groups(*components.map(&:group), *groups)
187
+ # Merges enabled Bootinq's groups with the given groups and, if loaded with Rails,
188
+ # passes them to <tt>Rails.groups</tt> method, otherwise just returns the merged list
189
+ # to use with <tt>Bundler.require</tt>.
190
+ delegated def groups(*groups)
191
+ groups.unshift(*components.map(&:group))
192
+ if defined?(Rails)
193
+ Rails.groups(*groups)
194
+ else
195
+ groups
196
+ end
127
197
  end
128
198
 
129
199
  # :call-seq:
@@ -149,7 +219,7 @@ class Bootinq
149
219
  # Bootinq.on all: %i(frontend backend) do
150
220
  # # do something when frontend and backend are enabled
151
221
  # end
152
- def on(name = nil, any: nil, all: nil) # :yields:
222
+ delegated def on(name = nil, any: nil, all: nil) # :yields:
153
223
  if name.nil? && any.nil? && all.nil?
154
224
  raise ArgumentError, "wrong arguments (given 0, expected 1)"
155
225
  elsif (any && all) || (name && (any || all))
@@ -169,7 +239,7 @@ class Bootinq
169
239
  #
170
240
  # Takes a list of component names and yields a given block (optionally)
171
241
  # if all of them are enabled. Returns boolean matching status.
172
- def on_all(*parts) # :yields:
242
+ delegated def on_all(*parts) # :yields:
173
243
  is_matched = parts.all? { |p| enabled?(p) }
174
244
  yield if is_matched && block_given?
175
245
  is_matched
@@ -180,12 +250,28 @@ class Bootinq
180
250
  #
181
251
  # Takes a list of component names and yields a given block (optionally)
182
252
  # if any of them are enabled. Returns boolean matching status.
183
- def on_any(*parts) # :yields:
253
+ delegated def on_any(*parts) # :yields:
184
254
  is_matched = parts.any? { |p| enabled?(p) }
185
255
  yield if is_matched && block_given?
186
256
  is_matched
187
257
  end
188
258
 
259
+ # :call-seq:
260
+ # Bottinq.switch(*parts) { block } -> nil
261
+ #
262
+ # Collector method.
263
+ #
264
+ # Example:
265
+ #
266
+ # Bootinq.switch do |part|
267
+ # part.frontend { … }
268
+ # part.backend { … }
269
+ # end
270
+ delegated def switch # :yields: Bootinq::Switch.new
271
+ yield(Switch.new)
272
+ nil
273
+ end
274
+
189
275
  # Freezes every instance variables and the instance itself.
190
276
  def freeze
191
277
  @_value.freeze
@@ -195,9 +281,7 @@ class Bootinq
195
281
  super
196
282
  end
197
283
 
198
- def_delegators "instance", *instance_methods(false)
199
-
200
- def self.new # :no-doc:
284
+ def self.new
201
285
  super.freeze
202
286
  end
203
287
 
@@ -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 inspect
32
- @intern.inspect
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 engine
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 module_name
39
- @id2name.camelcase.to_sym
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
- def respond_to_missing?(method_name, include_all=false)
43
- @intern.respond_to?(method_name, include_all)
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
- private
69
+ %i(encoding empty? length).
70
+ each { |sym| class_eval %(def #{sym}; @id2name.#{sym}; end), __FILE__, __LINE__ + 1 }
47
71
 
48
- def method_missing(method_name, *args, &blk)
49
- @intern.respond_to?(method_name) ? @intern.public_send(method_name, *args, &blk) : super
50
- end
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
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Bootinq
4
+ class Switch < ::BasicObject # :no-doc:
5
+ undef_method :==
6
+ undef_method :equal?
7
+
8
+ def raise(*args) # :no-doc:
9
+ ::Object.send(:raise, *args)
10
+ end
11
+
12
+ def method_missing(name, *)
13
+ if ::Bootinq.enabled?(name)
14
+ yield()
15
+ else
16
+ nil
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bootinq
4
- VERSION = "1.1.0"
4
+ VERSION = "1.4.1"
5
5
  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.1.0
4
+ version: 1.4.1
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-06 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - lib/bootinq.rb
59
59
  - lib/bootinq.yml
60
60
  - lib/bootinq/component.rb
61
+ - lib/bootinq/switch.rb
61
62
  - lib/bootinq/version.rb
62
63
  homepage: https://github.com/estum/bootinq
63
64
  licenses:
@@ -78,8 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  - !ruby/object:Gem::Version
79
80
  version: '0'
80
81
  requirements: []
81
- rubyforge_project:
82
- rubygems_version: 2.7.6
82
+ rubygems_version: 3.0.3
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Rails Boot Inquirer