bootinq 0.2.0 → 0.3.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/Gemfile +1 -0
- data/README.md +102 -8
- data/bootinq.gemspec +1 -1
- data/lib/bootinq/version.rb +1 -1
- data/lib/bootinq.rb +20 -5
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8647f4b798663b8511a3d2c7a9527b93756b9ca
|
4
|
+
data.tar.gz: 35bd6157a95de1bd4df9648896d08939401281cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cf0fc21e41449527782916a81a3dfb2749f6e9f91dda590d381a5b5dd15bc31c5d15b6216fdf1cb717424cd83a069b09a3fab213a657a041700ae313fe9a8df
|
7
|
+
data.tar.gz: add219d5df6e7a54aae76552de7be7f5509d79fdb51541399f3705f3c0f025de28b19b396374b842e92fd6ae96591bb2284b66acb75ceff8a3b500477d83f748
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -14,27 +14,122 @@ And then execute:
|
|
14
14
|
|
15
15
|
$ bundle
|
16
16
|
|
17
|
-
Insert `require "bootinq"` to the top of `config/application.rb` file.
|
18
17
|
|
19
|
-
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
There are few steps to setup partial gem booting in a Rails application using Bootinq:
|
21
|
+
|
22
|
+
### 1. Declare loadable parts
|
23
|
+
|
24
|
+
The environment variable specifies which parts should be loaded using the assigned char keys. If the value is starts with `-`, all parts except the given will be loaded.
|
25
|
+
|
26
|
+
For example, looking at the configuration below, if we want to load only `api`, we should set `BOOTINQ=a`. If we want to load the all except `frontend` and `admin`, we should set `BOOTINQ=-fz`.
|
20
27
|
|
21
|
-
|
28
|
+
The name of the environment variable can be customized by changing the `env_key:`
|
22
29
|
|
23
30
|
```yaml
|
31
|
+
# config/bootinq.yml
|
24
32
|
env_key: BOOTINQ
|
25
33
|
default: "-f"
|
26
34
|
|
35
|
+
# Non-mountable parts
|
27
36
|
parts:
|
28
|
-
|
37
|
+
c: :console
|
29
38
|
|
39
|
+
# Mountable parts (engines)
|
30
40
|
mount:
|
31
41
|
a: :api
|
32
|
-
f: :
|
42
|
+
f: :frontend
|
43
|
+
z: :admin
|
33
44
|
```
|
34
45
|
|
35
|
-
|
46
|
+
### 2. Add gem groups
|
47
|
+
|
48
|
+
For each app part you should add a gem group named as `#{group_name}_boot`:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Gemfile
|
52
|
+
|
53
|
+
gem "api", path: "apps/api", group: :api_boot
|
54
|
+
gem "admin", path: "apps/admin", group: :admin_boot
|
55
|
+
gem "frontend", path: "apps/frontend", group: :frontend_boot
|
56
|
+
|
57
|
+
group :console_boot do
|
58
|
+
gem 'term-ansicolor', '1.1.5'
|
59
|
+
gem 'pry-rails'
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
### 3. Change config/application.rb
|
64
|
+
|
65
|
+
Insert `require "bootinq"` to the top of `config/application.rb` file and replace `Bundler.require(*Rails.groups)` with the `Bootinq.require`:
|
66
|
+
|
67
|
+
#### Simple
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# config/application.rb
|
71
|
+
|
72
|
+
require File.expand_path('../boot', __FILE__)
|
73
|
+
require 'rails/all'
|
74
|
+
require 'bootinq'
|
36
75
|
|
37
|
-
|
76
|
+
# With no additional gem groups:
|
77
|
+
Bootinq.require
|
78
|
+
# otherwise, set them like in <tt>Bundle.require(*Rails.groups(*groups))</tt>:
|
79
|
+
# Bootinq.require(:assets => %w(development test))
|
80
|
+
|
81
|
+
puts "* Bootinq: loading components #{Bootinq.components * ', '}"
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Separate load rails components with Bootinq
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
# config/application.rb
|
88
|
+
require File.expand_path('../boot', __FILE__)
|
89
|
+
|
90
|
+
require "rails"
|
91
|
+
# Pick the frameworks you want:
|
92
|
+
require "active_model/railtie"
|
93
|
+
require "active_record/railtie"
|
94
|
+
require "active_job/railtie"
|
95
|
+
require "action_mailer/railtie"
|
96
|
+
require "rails/test_unit/railtie"
|
97
|
+
|
98
|
+
Bootinq.require do
|
99
|
+
# Load the following components only when the frontend component is enabled
|
100
|
+
on :frontend do
|
101
|
+
require "sprockets/railtie"
|
102
|
+
require "action_controller/railtie"
|
103
|
+
require "action_view/railtie"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
### 4. Mount enabled engines in config/routes.rb
|
109
|
+
|
110
|
+
Use the `Bootinq.each_mountable {}` helper to easily mount currently loaded engines or do it by yourself checking `Bootinq.enabled?(engine_name)` :
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# config/routes.rb
|
114
|
+
Rails.application.routes.draw do
|
115
|
+
Bootinq.each_mountable do |part|
|
116
|
+
mount part.engine => '/', as: part.to_sym
|
117
|
+
end
|
118
|
+
|
119
|
+
root 'frontend/pages#index' if Bootinq.enabled?(:frontend)
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
### 5. Run app with only wanted parts
|
124
|
+
|
125
|
+
Now, you can set environment variable to tell workers which part of app it should load.
|
126
|
+
|
127
|
+
For example, with the [foreman](https://github.com/ddollar/foreman) in `Procfile`:
|
128
|
+
|
129
|
+
```
|
130
|
+
api: env BOOTINQ=a MAX_THREADS=128 bundle exec puma -w 4
|
131
|
+
admin: env BOOTINQ=z bundle exec puma
|
132
|
+
```
|
38
133
|
|
39
134
|
## Development
|
40
135
|
|
@@ -45,4 +140,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
45
140
|
## Contributing
|
46
141
|
|
47
142
|
Bug reports and pull requests are welcome on GitHub at https://github.com/estum/bootinq.
|
48
|
-
|
data/bootinq.gemspec
CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.summary = %q{Rails Boot Inquirer}
|
13
13
|
spec.description = %q{Allows to select which bundle groups to boot in the current rails process}
|
14
14
|
spec.homepage = "https://github.com/estum/bootinq"
|
15
|
+
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
18
|
spec.bindir = "exe"
|
@@ -20,5 +21,4 @@ Gem::Specification.new do |spec|
|
|
20
21
|
|
21
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
22
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
-
spec.add_development_dependency "rspec"
|
24
24
|
end
|
data/lib/bootinq/version.rb
CHANGED
data/lib/bootinq.rb
CHANGED
@@ -81,17 +81,32 @@ class Bootinq
|
|
81
81
|
end
|
82
82
|
|
83
83
|
# Invokes <tt>Rails.groups</tt> method within enabled Bootinq's groups
|
84
|
-
def groups(*
|
85
|
-
Rails.groups(*components.map(&:group), *
|
84
|
+
def groups(*list)
|
85
|
+
Rails.groups(*components.map(&:group), *list)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Yields the given block if any of given components is enabled.
|
89
|
+
#
|
90
|
+
# ==== Example:
|
91
|
+
#
|
92
|
+
# Bootinq.on :frontend do
|
93
|
+
# # make frontend thing...
|
94
|
+
# end
|
95
|
+
def on(*names) # :yields:
|
96
|
+
if names.any? { |name| enabled?(name) }
|
97
|
+
yield
|
98
|
+
end
|
86
99
|
end
|
87
100
|
|
88
101
|
def_delegators "instance", *instance_methods(false)
|
89
102
|
|
90
103
|
class << self
|
91
|
-
# The helper method to bootstrap the Bootinq.
|
92
|
-
#
|
93
|
-
|
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:
|
94
108
|
ENV['BOOTINQ_PATH'] ||= File.expand_path('../bootinq.yml', caller_locations(1..1)[0].path)
|
109
|
+
instance.instance_exec(&block) if block_given?
|
95
110
|
Bundler.require(*instance.groups(*groups))
|
96
111
|
end
|
97
112
|
|
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.3.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-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
description: Allows to select which bundle groups to boot in the current rails process
|
56
42
|
email:
|
57
43
|
- anton.estum@gmail.com
|
@@ -74,7 +60,8 @@ files:
|
|
74
60
|
- lib/bootinq/version.rb
|
75
61
|
- lib/tasks/bootinq_tasks.rake
|
76
62
|
homepage: https://github.com/estum/bootinq
|
77
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
78
65
|
metadata: {}
|
79
66
|
post_install_message:
|
80
67
|
rdoc_options: []
|