bootinq 0.3.0 → 0.5.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
2
  SHA1:
3
- metadata.gz: a8647f4b798663b8511a3d2c7a9527b93756b9ca
4
- data.tar.gz: 35bd6157a95de1bd4df9648896d08939401281cb
3
+ metadata.gz: 7902442d51cbd75049e152e1e7c4097c7f9d8d1f
4
+ data.tar.gz: 66efaa0d93126ee982e8a6fdad02f3fbe54de614
5
5
  SHA512:
6
- metadata.gz: 8cf0fc21e41449527782916a81a3dfb2749f6e9f91dda590d381a5b5dd15bc31c5d15b6216fdf1cb717424cd83a069b09a3fab213a657a041700ae313fe9a8df
7
- data.tar.gz: add219d5df6e7a54aae76552de7be7f5509d79fdb51541399f3705f3c0f025de28b19b396374b842e92fd6ae96591bb2284b66acb75ceff8a3b500477d83f748
6
+ metadata.gz: e68317bb8356171fbe0aac37eb41e64c64d7133791bf5d4dc92bacc394d2ea58d157af1f9d71d3e2c1b431ab0f43a66ec30b3eba6cf4c3e3ecb05877b1f16a0e
7
+ data.tar.gz: 930826fe693f9ad2bea46b8e6ca7a795dc4afc417476e925f5597814748a5cce2bae6056776682d0447ee8a7030afa194787473c9c98ebd0643778c13d03a349
data/.gitignore CHANGED
@@ -13,4 +13,5 @@
13
13
  /spec/dummy/log/*.log
14
14
  /spec/dummy/tmp/
15
15
  /spec/dummy/.sass-cache
16
- .rake_t_cache
16
+ .rake_t_cache
17
+ .ruby-version
@@ -1,20 +1,64 @@
1
1
  class Bootinq
2
- class Component < DelegateClass(Symbol)
3
- attr_reader :gem_name, :mountable, :namespace, :group
4
- alias :to_s :gem_name
5
- alias :mountable? :mountable
6
-
7
- def initialize(name, mountable: false)
8
- super(name)
9
- @gem_name = name.to_s.freeze
10
- @mountable = !!mountable
11
- @group = :"#{gem_name}_boot"
12
- @namespace = :"#{gem_name.camelcase}" if mountable?
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(@namespace)::Engine
61
+ Object.const_get(module_name)::Engine
18
62
  end
19
63
  end
20
64
  end
@@ -1,3 +1,3 @@
1
1
  class Bootinq
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
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
- NEG = '-'.freeze
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
- attr_reader :flags, :components
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
- include Singleton
39
- extend SingleForwardable
44
+ logger.debug { "Bootinq: loading components #{instance.components.join(', ')}" } if logger.respond_to?(:debug)
40
45
 
41
- def initialize
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
- config['parts'].merge!(config['mount'])
48
+ Bundler.require(*instance.groups(*groups))
49
+ end
47
50
 
48
- value = ENV[config['env_key']] || config['default'].to_s
49
- neg = value.start_with?(NEG)
51
+ private_class_method def self.new # :nodoc:
52
+ super.freeze
53
+ end
50
54
 
51
- flags = []
52
- parts = []
53
55
 
54
- config['parts'].each do |flag, name|
55
- if neg ^ value[flag]
56
- flags << flag
57
- parts << Component.new(name, mountable: config['mount'].key?(flag))
58
- end
59
- end
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
- @_value = value.freeze
62
- @_neg = neg.freeze
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 { |c| yield(c) if c.mountable? }
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
- # Yields the given block if any of given components is enabled.
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
- def on(*names) # :yields:
96
- if names.any? { |name| enabled?(name) }
97
- yield
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
- def_delegators "instance", *instance_methods(false)
124
+ def freeze # :no-doc:
125
+ @_value.freeze
126
+ @_neg.freeze
127
+ @flags.freeze
128
+ @components.freeze
129
+ super
130
+ end
102
131
 
103
- class << self
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
- private def new
114
- super.freeze
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.3.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: 2015-10-26 00:00:00.000000000 Z
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.4.8
82
+ rubygems_version: 2.5.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Rails Boot Inquirer