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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e3f02fce19c9b509420de6322555b1f3a8fe7c2a
4
- data.tar.gz: 1a269f11b486f95c33d6df89948281cb74d6e2f6
2
+ SHA256:
3
+ metadata.gz: f503e7ad103931ee10ce325a3590e3b7742f128a6947a37f59a1566ec57ceaed
4
+ data.tar.gz: 750b19a788035d9325cff83342cc67e2aac08b9ef4e892637eee07121a73b7b4
5
5
  SHA512:
6
- metadata.gz: efc41497347123f8025457ad4af3e2037df51387f56248ece3bcdacfb0443eae8f12428203a4dda3a8e3d1d19a8ef21e32687eafdb01475486dc00c02a06f808
7
- data.tar.gz: 274f3d80999d1acacf21ceeafea979fd67a138ed617959effa234b860331599109e71c3cd5c964c11c93c4d4fead1dafec65521326e76a9a3344199b69e1e651
6
+ metadata.gz: f2878d2f0977783d2d586baa923bbc80945a2495120b522a5c198fd0c493c21f9b7ab4f591799b4f041130cfb62e3747f9287683d23db0bbccf92a64716fac49
7
+ data.tar.gz: 15eac28f64c7777dcafefb756d4a6e3644d22561c673bada3e5d6ff7187283d7596a8c62aae2e1933cab49e1f44531570a99c32e37b1db5a69e4fda4cf66eb34
data/Gemfile CHANGED
@@ -10,7 +10,7 @@ gemspec
10
10
  # Git. Remember to move these dependencies to your gemspec before releasing
11
11
  # your gem to rubygems.org.
12
12
 
13
- gem 'rails', '~> 4.2'
13
+ gem 'rails', '>= 5.0'
14
14
  gem 'sqlite3'
15
15
 
16
16
  # To use a debugger
@@ -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", "~> 1.10"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
24
  end
@@ -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, yields optional block in
39
- # the own instance's binding and, finally, requires selected bundler groups.
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
- puts "Bootinq: loading components #{instance.components.join(', ')}" if verbose
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
- private_class_method def self.new # :nodoc:
51
- super.freeze
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
- config = YAML.safe_load(File.read(ENV.fetch('BOOTINQ_PATH')), [Symbol]).
59
- merge!(DEFAULT) { |_,l,r| l.nil? ? r : l }
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) { Component.new(name) } }
67
- config['mount'].each { |flag, name| enable_component(flag) { Mountable.new(name) } }
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
- # Checks if a given gem (i.e. a gem group) is enabled
71
- def enabled?(gem_name)
72
- components.include?(gem_name)
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(key)
77
- components[components.index(key)]
102
+ def component(name)
103
+ components[components.index(name)]
78
104
  end
79
105
 
80
106
  alias :[] :component
81
107
 
82
- # Enums each mountable component
83
- def each_mountable # :yields:
84
- return to_enum(__method__) unless block_given?
85
- components.each { |part| yield(part) if part.mountable? }
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(*list)
90
- Rails.groups(*components.map(&:group), *list)
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 (any && all) || (name && (any || all))
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
- def freeze # :no-doc:
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
- private def enable_component(flag) # :yields:
136
- if @_neg ^ @_value.include?(flag)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Bootinq
2
4
  class Component
3
5
  attr_reader :intern, :id2name, :group
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Bootinq
2
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
3
5
  end
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.1
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: 2016-07-02 00:00:00.000000000 Z
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: '1.10'
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: '1.10'
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: '10.0'
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: '10.0'
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.6.6
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:
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :bootinq do
3
- # # Task goes here
4
- # end