bootinq 1.5 → 1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bootinq.rb +40 -26
  3. data/lib/bootinq/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1e1d6c92b8790ff798d3ac3af73aa4d1ba51d65e5d30a710e71b109dff4a1d2
4
- data.tar.gz: ff41e0be38f693a836592446d3a8600613497595228075a325bfa3cd06a36585
3
+ metadata.gz: 33cdc97b02b2407bf6cf031dbac9e0fdae903d6a97a60e266b058729d6a43895
4
+ data.tar.gz: 1cba1d8a6a48ff92ba80dbcad36623a7389f95f512b8d844debc5c7c22644e6b
5
5
  SHA512:
6
- metadata.gz: f6d003846a5991fef4e37aaf9ab72c03878eaaecb98b0b347b8ac537f4d583a880b578bda284ec1d1539396b3a822a0d72511cf349d54cb6638892052768a563
7
- data.tar.gz: 28a35e3389f226c94126dc11adcecbdde73cb6b8b9b02876ffb987cddaec8f0d32274e3831d61ba163c64bde0eebe00c505bb0b24c7aa3032e445e840fb350dd
6
+ metadata.gz: 7a4b636bbdea12800a0b367bd5e4294c9681738200597100725595bd3ce3f4f6a5d4b95c14594249cba8755fa11206ba6a01fc516923e1e72493a34efbb79b1d
7
+ data.tar.gz: b6c5e5d242ffff08ac9f00a680dd760979879769e9a752193e039453f31d86684ce97f9d7e19167e36de4ede4003ae9e7a1e42647288082e36bee6badd58095e
data/lib/bootinq.rb CHANGED
@@ -73,15 +73,6 @@ class Bootinq
73
73
 
74
74
  private_constant :FilterNegValue
75
75
 
76
- class << self
77
- protected def delegated(sym) # :no-doc:
78
- location = caller_locations(1, 1).first
79
- file, line = location.path, location.lineno
80
- definiton = %(def self.#{sym}(*args, &block); instance.#{sym}(*args, &block); end)
81
- class_eval definiton, file, line
82
- end
83
- end
84
-
85
76
  # :call-seq:
86
77
  # Bootinq.require(*groups, verbose: false, &block)
87
78
  #
@@ -117,15 +108,17 @@ class Bootinq
117
108
  instance.ready!
118
109
  end
119
110
 
111
+ # Reads config from the given or default path, deserializes it and returns as a hash.
112
+ def self.deserialized_config(path: nil)
113
+ bootinq_yaml = File.read(path || ENV.fetch('BOOTINQ_PATH'))
114
+ YAML.safe_load(bootinq_yaml, [Symbol])
115
+ end
116
+
120
117
  attr_reader :flags
121
118
  attr_reader :components
122
119
 
123
- delegated :flags
124
- delegated :components
125
-
126
120
  def initialize # :no-doc:
127
- config_path = ENV.fetch('BOOTINQ_PATH')
128
- config = YAML.safe_load(File.read(config_path), [Symbol])
121
+ config = self.class.deserialized_config
129
122
  config.merge!(DEFAULT) { |_, l, r| l.nil? ? r : l }
130
123
 
131
124
  @_orig_value = ENV.fetch(config['env_key']) { config['default'] }
@@ -140,7 +133,7 @@ class Bootinq
140
133
  config['mount'].each { |flag, name| enable_component(name, flag: flag.to_s, as: Mountable) }
141
134
  end
142
135
 
143
- delegated def ready? # :no-doc:
136
+ def ready? # :no-doc:
144
137
  !!@ready
145
138
  end
146
139
 
@@ -149,7 +142,7 @@ class Bootinq
149
142
  #
150
143
  # At the first call marks Bootinq as ready and returns the instance,
151
144
  # otherwise returns nil.
152
- delegated def ready!
145
+ def ready!
153
146
  return if ready?
154
147
  @ready = true
155
148
  if defined?(@_on_ready)
@@ -162,7 +155,7 @@ class Bootinq
162
155
  # :call-seq:
163
156
  # Bootinq.enable_component(name, flag: [, as: Component])
164
157
  #
165
- delegated def enable_component(name, flag:, as: Component)
158
+ def enable_component(name, flag:, as: Component)
166
159
  if is_dependency?(name) || @_value.include?(flag)
167
160
  @flags << flag
168
161
  @components << as.new(name)
@@ -174,7 +167,7 @@ class Bootinq
174
167
  #
175
168
  # Checks if a component with the given name (i.e. the same gem group)
176
169
  # is enabled
177
- delegated def enabled?(name)
170
+ def enabled?(name)
178
171
  components.include?(name)
179
172
  end
180
173
 
@@ -183,12 +176,11 @@ class Bootinq
183
176
  # Bootinq[name] -> Bootinq::Component
184
177
  #
185
178
  # Returns a <tt>Bootinq::Component</tt> object by its name
186
- delegated def component(name)
179
+ def component(name)
187
180
  components[components.index(name)]
188
181
  end
189
182
 
190
183
  alias :[] :component
191
- delegated :[]
192
184
 
193
185
  # :call-seq:
194
186
  # Bootinq.each_mountable { |part| block } -> Array
@@ -198,7 +190,7 @@ class Bootinq
198
190
  # passing that part as a parameter. Returns the array of all mountable components.
199
191
  #
200
192
  # If no block is given, an Enumerator is returned.
201
- delegated def each_mountable(&block) # :yields: part
193
+ def each_mountable(&block) # :yields: part
202
194
  components.select(&:mountable?).each(&block)
203
195
  end
204
196
 
@@ -208,7 +200,7 @@ class Bootinq
208
200
  # Merges enabled Bootinq's groups with the given groups and, if loaded with Rails,
209
201
  # passes them to <tt>Rails.groups</tt> method, otherwise just returns the merged list
210
202
  # to use with <tt>Bundler.require</tt>.
211
- delegated def groups(*groups)
203
+ def groups(*groups)
212
204
  groups.unshift(*components.map(&:group))
213
205
  if defined?(Rails)
214
206
  Rails.groups(*groups)
@@ -240,7 +232,7 @@ class Bootinq
240
232
  # Bootinq.on all: %i(frontend backend) do
241
233
  # # do something when frontend and backend are enabled
242
234
  # end
243
- delegated def on(name = nil, any: nil, all: nil) # :yields:
235
+ def on(name = nil, any: nil, all: nil) # :yields:
244
236
  if name.nil? && any.nil? && all.nil?
245
237
  raise ArgumentError, "wrong arguments (given 0, expected 1)"
246
238
  elsif (any && all) || (name && (any || all))
@@ -260,7 +252,7 @@ class Bootinq
260
252
  #
261
253
  # Takes a list of component names and yields a given block (optionally)
262
254
  # if all of them are enabled. Returns boolean matching status.
263
- delegated def on_all(*parts) # :yields:
255
+ def on_all(*parts) # :yields:
264
256
  is_matched = parts.all? { |p| enabled?(p) }
265
257
  yield if is_matched && block_given?
266
258
  is_matched
@@ -271,7 +263,7 @@ class Bootinq
271
263
  #
272
264
  # Takes a list of component names and yields a given block (optionally)
273
265
  # if any of them are enabled. Returns boolean matching status.
274
- delegated def on_any(*parts) # :yields:
266
+ def on_any(*parts) # :yields:
275
267
  is_matched = parts.any? { |p| enabled?(p) }
276
268
  yield if is_matched && block_given?
277
269
  is_matched
@@ -288,7 +280,7 @@ class Bootinq
288
280
  # part.frontend { … }
289
281
  # part.backend { … }
290
282
  # end
291
- delegated def switch # :yields: Bootinq::Switch.new
283
+ def switch # :yields: Bootinq::Switch.new
292
284
  yield(Switch.new)
293
285
  nil
294
286
  end
@@ -309,4 +301,26 @@ class Bootinq
309
301
  @components.freeze
310
302
  super
311
303
  end
304
+
305
+ delegate_template = <<~RUBY
306
+ def self.%1$s(*args, &block)
307
+ instance.%1$s(*args, &block)
308
+ end
309
+ RUBY
310
+
311
+ %I(flags
312
+ components
313
+ ready?
314
+ ready!
315
+ enable_component
316
+ enabled?
317
+ component
318
+ []
319
+ each_mountable
320
+ groups
321
+ on
322
+ on_all
323
+ on_any
324
+ switch
325
+ ).each { |sym| class_eval(delegate_template % sym, *instance_method(sym).source_location) }
312
326
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Bootinq
4
- VERSION = "1.5"
4
+ VERSION = "1.6"
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.5'
4
+ version: '1.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-31 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler