bootinq 0.3.0 → 0.5.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/.gitignore +2 -1
- data/lib/bootinq/component.rb +56 -12
- data/lib/bootinq/version.rb +1 -1
- data/lib/bootinq.rb +65 -42
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7902442d51cbd75049e152e1e7c4097c7f9d8d1f
|
4
|
+
data.tar.gz: 66efaa0d93126ee982e8a6fdad02f3fbe54de614
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e68317bb8356171fbe0aac37eb41e64c64d7133791bf5d4dc92bacc394d2ea58d157af1f9d71d3e2c1b431ab0f43a66ec30b3eba6cf4c3e3ecb05877b1f16a0e
|
7
|
+
data.tar.gz: 930826fe693f9ad2bea46b8e6ca7a795dc4afc417476e925f5597814748a5cce2bae6056776682d0447ee8a7030afa194787473c9c98ebd0643778c13d03a349
|
data/.gitignore
CHANGED
data/lib/bootinq/component.rb
CHANGED
@@ -1,20 +1,64 @@
|
|
1
1
|
class Bootinq
|
2
|
-
class Component
|
3
|
-
attr_reader :
|
4
|
-
|
5
|
-
alias :
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
2
|
+
class Component
|
3
|
+
attr_reader :intern, :id2name
|
4
|
+
|
5
|
+
alias :to_sym :intern
|
6
|
+
alias :to_s :id2name
|
7
|
+
alias :gem_name :id2name
|
8
|
+
alias :name :id2name
|
9
|
+
|
10
|
+
def initialize(intern)
|
11
|
+
@intern = intern.to_sym
|
12
|
+
@id2name = intern.to_s.freeze
|
13
13
|
freeze
|
14
14
|
end
|
15
15
|
|
16
|
+
def mountable?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
|
20
|
+
def group
|
21
|
+
:"#@id2name\_boot"
|
22
|
+
end
|
23
|
+
|
24
|
+
def == other
|
25
|
+
case other
|
26
|
+
when String then other == @id2name
|
27
|
+
when Symbol then other == @intern
|
28
|
+
else super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def inspect
|
33
|
+
@intern.inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
def engine
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def module_name
|
41
|
+
@id2name.camelcase.to_sym
|
42
|
+
end
|
43
|
+
|
44
|
+
def respond_to_missing?(method_name, include_all=false)
|
45
|
+
@intern.respond_to?(method_name, include_all)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def method_missing(method_name, *args, &blk)
|
51
|
+
@intern.respond_to?(method_name) ? @intern.public_send(method_name, *args, &blk) : super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Mountable < Component
|
56
|
+
def mountable?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
16
60
|
def engine
|
17
|
-
Object.const_get(
|
61
|
+
Object.const_get(module_name)::Engine
|
18
62
|
end
|
19
63
|
end
|
20
64
|
end
|
data/lib/bootinq/version.rb
CHANGED
data/lib/bootinq.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "yaml"
|
2
|
-
require "erb"
|
3
2
|
require "singleton"
|
4
3
|
require "forwardable"
|
5
4
|
require "bootinq/component"
|
@@ -25,43 +24,48 @@ require "bootinq/component"
|
|
25
24
|
# a: :api
|
26
25
|
# f: :engine
|
27
26
|
class Bootinq
|
28
|
-
|
27
|
+
extend SingleForwardable
|
28
|
+
include Singleton
|
29
|
+
|
30
|
+
NEG_OPS = %w(- ^).freeze
|
29
31
|
DEFAULT = {
|
30
32
|
"env_key" => 'BOOTINQ',
|
31
33
|
"default" => '',
|
32
34
|
"parts" => {},
|
33
35
|
"mount" => {}
|
34
|
-
}
|
36
|
+
}.freeze
|
35
37
|
|
36
|
-
|
38
|
+
# The helper method to bootstrap the Bootinq.
|
39
|
+
# Sets the BOOTINQ_PATH enviroment variable, yields optional block in
|
40
|
+
# the own instance's binding and, finally, requires selected bundler groups.
|
41
|
+
def self.require(*groups, logger: nil, &block) # :yields:
|
42
|
+
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
|
37
43
|
|
38
|
-
|
39
|
-
extend SingleForwardable
|
44
|
+
logger.debug { "Bootinq: loading components #{instance.components.join(', ')}" } if logger.respond_to?(:debug)
|
40
45
|
|
41
|
-
|
42
|
-
config = YAML.load(File.read(ENV['BOOTINQ_PATH']))
|
43
|
-
config.reject! { |_, v| v.nil? }
|
44
|
-
config.reverse_merge!(DEFAULT)
|
46
|
+
instance.instance_exec(&block) if block_given?
|
45
47
|
|
46
|
-
|
48
|
+
Bundler.require(*instance.groups(*groups))
|
49
|
+
end
|
47
50
|
|
48
|
-
|
49
|
-
|
51
|
+
private_class_method def self.new # :nodoc:
|
52
|
+
super.freeze
|
53
|
+
end
|
50
54
|
|
51
|
-
flags = []
|
52
|
-
parts = []
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
attr_reader :flags, :components
|
57
|
+
|
58
|
+
def initialize
|
59
|
+
config = YAML.safe_load(File.read(ENV.fetch('BOOTINQ_PATH')), [Symbol]).
|
60
|
+
merge!(DEFAULT) { |_,l,r| l.nil? ? r : l }
|
61
|
+
|
62
|
+
@_value = ENV.fetch(config['env_key']) { config['default'] }
|
63
|
+
@_neg = @_value.start_with?(*NEG_OPS)
|
64
|
+
@flags = []
|
65
|
+
@components = []
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
@flags = flags.freeze
|
64
|
-
@components = parts.freeze
|
67
|
+
config['parts'].each { |flag, name| enable_component(flag) { Component.new(name) } }
|
68
|
+
config['mount'].each { |flag, name| enable_component(flag) { Mountable.new(name) } }
|
65
69
|
end
|
66
70
|
|
67
71
|
# Checks if a given gem (i.e. a gem group) is enabled
|
@@ -74,10 +78,12 @@ class Bootinq
|
|
74
78
|
components[components.index(key)]
|
75
79
|
end
|
76
80
|
|
81
|
+
alias :[] :component
|
82
|
+
|
77
83
|
# Enums each mountable component
|
78
84
|
def each_mountable
|
79
85
|
return to_enum(__method__) unless block_given?
|
80
|
-
components.each { |
|
86
|
+
components.each { |part| yield(part) if part.mountable? }
|
81
87
|
end
|
82
88
|
|
83
89
|
# Invokes <tt>Rails.groups</tt> method within enabled Bootinq's groups
|
@@ -85,33 +91,50 @@ class Bootinq
|
|
85
91
|
Rails.groups(*components.map(&:group), *list)
|
86
92
|
end
|
87
93
|
|
88
|
-
#
|
94
|
+
# Takes a component's name or single-key options hash as an argument and
|
95
|
+
# yields a given block if the target components are enabled.
|
96
|
+
#
|
97
|
+
# See examples for a usage.
|
89
98
|
#
|
90
99
|
# ==== Example:
|
91
100
|
#
|
92
101
|
# Bootinq.on :frontend do
|
93
102
|
# # make frontend thing...
|
94
103
|
# end
|
95
|
-
|
96
|
-
|
97
|
-
|
104
|
+
#
|
105
|
+
# Bootinq.on any: %i(frontend backend) do
|
106
|
+
# # do something when frontend or backend is enabled
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
# Bootinq.on all: %i(frontend backend) do
|
110
|
+
# # do something when frontend and backend are enabled
|
111
|
+
# end
|
112
|
+
def on(name) # :yields:
|
113
|
+
if name.is_a?(Hash)
|
114
|
+
%i(any all).each do |m|
|
115
|
+
list = name[m]
|
116
|
+
next unless list.is_a?(Enumerable)
|
117
|
+
yield if list.public_send(:"#{m}?") { |part| enabled?(part) }
|
118
|
+
end
|
119
|
+
else
|
120
|
+
yield if enabled?(name)
|
98
121
|
end
|
99
122
|
end
|
100
123
|
|
101
|
-
|
124
|
+
def freeze # :no-doc:
|
125
|
+
@_value.freeze
|
126
|
+
@_neg.freeze
|
127
|
+
@flags.freeze
|
128
|
+
@components.freeze
|
129
|
+
super
|
130
|
+
end
|
102
131
|
|
103
|
-
|
104
|
-
# The helper method to bootstrap the Bootinq.
|
105
|
-
# Sets the BOOTINQ_PATH enviroment variable, yields optional block in
|
106
|
-
# the own instance's binding and, finally, requires selected bundler groups.
|
107
|
-
def require(*groups, &block) # :yields:
|
108
|
-
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
|
109
|
-
instance.instance_exec(&block) if block_given?
|
110
|
-
Bundler.require(*instance.groups(*groups))
|
111
|
-
end
|
132
|
+
def_delegators "instance", *instance_methods(false)
|
112
133
|
|
113
|
-
|
114
|
-
|
134
|
+
private def enable_component(flag) # :yields:
|
135
|
+
if @_neg ^ @_value.include?(flag)
|
136
|
+
@flags << flag
|
137
|
+
@components << yield
|
115
138
|
end
|
116
139
|
end
|
117
140
|
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: 0.
|
4
|
+
version: 0.5.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: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.5.1
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Rails Boot Inquirer
|