heavy_control 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08e7942c5b0ff2f50c6789dc6ba6bcd94df3a360
4
+ data.tar.gz: 1a18431ca2cee0e11df32a86a227f9f06c90dd64
5
+ SHA512:
6
+ metadata.gz: ce2fb2c1e7a5e7cbe67ef8a9dee248f25bea372a1bbd901b1d973e97333997870540f38e98eea23032e61ac19ef8e323f407e2049adf59b63f07263fec3905eb
7
+ data.tar.gz: 3e21e424e0707ecea61fe762db22fb969a820f1cfa48e042485a0166526a8de0b93d944732876956b69e5ba0188ab52ba6968e4c91589f2ce949a29c94ccbfdb
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'vendor/**/*'
5
+ - 'spec/dummies/**/*'
6
+ - 'gemfiles/**/*'
7
+
8
+ Rails:
9
+ Enabled: true
10
+
11
+ LineLength:
12
+ Enabled: false
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/ClassAndModuleChildren:
18
+ Enabled: false
19
+
20
+ Style/FileName:
21
+ Exclude:
22
+ - Appraisals
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ sudo: false
4
+
5
+ matrix:
6
+ include:
7
+ - rvm: 2.3.1
8
+ script:
9
+ - bundle exec rake rubocop
10
+ - rvm: 2.3.1
11
+ gemfile: gemfiles/rails_4.2.gemfile
12
+ - rvm: 2.3.1
13
+ gemfile: gemfiles/rails_5.0.gemfile
14
+ - rvm: 2.2.5
15
+ gemfile: gemfiles/rails_4.2.gemfile
16
+ - rvm: 2.2.5
17
+ gemfile: gemfiles/rails_5.0.gemfile
data/Appraisals ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ appraise 'rails-4.2' do
3
+ gem 'rails', '~> 4.2'
4
+ end
5
+
6
+ appraise 'rails-5.0' do
7
+ gem 'rails', '~> 5.0'
8
+ end
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in heavy_control.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # HeavyControl
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/heavy_control.svg)](http://badge.fury.io/rb/heavy_control)
4
+ [![Build Status](https://travis-ci.org/ffloyd/heavy_control.svg?branch=master)](https://travis-ci.org/ffloyd/heavy_control)
5
+ [![Code Climate](https://codeclimate.com/github/ffloyd/heavy_control.svg)](https://codeclimate.com/github/ffloyd/heavy_control)
6
+ [![git.legal](https://git.legal/projects/1859/badge.svg "Number of libraries approved")](https://git.legal/projects/1859)
7
+
8
+ HeavyControl adds tools which allows you to modify Rails autoloading logic.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'heavy_control'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Rails 4.2 and 5.0 are supported by this gem.
23
+
24
+ ## Usage
25
+
26
+ Create initializer and place HeavyControl config inside:
27
+
28
+ ```ruby
29
+ # config/initializers/heavy_control.rb
30
+ HeavyControl.config do
31
+ # example config:
32
+ ignore_subfolder 'operations'
33
+ always_load 'SomeClass'
34
+ end
35
+ ```
36
+
37
+ HeavyControl resolves several problems related to Rails' autoloading:
38
+
39
+ * Debugging
40
+ * Ignore subfolders while constant resolving
41
+ * 'Toplevel constant referenced' situations
42
+
43
+ ### Debugging
44
+
45
+ It may be useful to debug autoloading behaviour. To enable this feature just add `debug` to HeavyControl config:
46
+
47
+ ```ruby
48
+ # config/initializers/heavy_control.rb
49
+ HeavyControl.config do
50
+ debug
51
+ end
52
+ ```
53
+
54
+ And you will get logs on `DEBUG` level via `Rails.logger`. Like this:
55
+
56
+ ```
57
+ HeavyControl: Load missing constant 'Organization' from Object
58
+ HeavyControl: Search for file with suffix 'organization'
59
+ HeavyControl: and found '/vagrant/app/models/organization.rb'
60
+ HeavyControl: Require of load '/vagrant/app/models/organization' with const_path 'Organization'
61
+ ```
62
+
63
+ ### Ignore subfolders
64
+
65
+ Rails automatically adds all folders under `/app` into autoloading paths. When you use constant (class, module) first time autoloading will search for file
66
+ with implementation. File path calculation is based on naming convention. So, for `YourContext::YourClass` it will be `[RAILS_ROOT]/app/[ANY_FOLDER]/your_context/your_class.rb`.
67
+
68
+ But sometimes (when we use [trailblazer](http://trailblazer.to/), as example) we want to split our files into subfolders without affecting their namespaces. In other words we want `YourContext::YourClass` to be found in `app/whatever/your_context/your_class.rb` OR `app/whatever/your_context/subfolder/your_class.rb`. To achieve this you should add `ignore_subfolder` option to HeavyControl's config:
69
+
70
+ ```ruby
71
+ # config/initializers/heavy_control.rb
72
+ HeavyControl.config do
73
+ ignore_subfolder 'subfolder'
74
+ end
75
+ ```
76
+
77
+ ### 'Toplevel constant referenced' situations
78
+
79
+ Sometimes we can get errors related to warnings like this:
80
+
81
+ ```
82
+ warning: toplevel constant YourClass referenced by YourContext::YourClass
83
+ ```
84
+
85
+ Classic solution is using of `require_dependency` method. HeavyControl brings another approach: `always_load` option. Solution for given warning will be:
86
+
87
+ ```ruby
88
+ # config/initializers/heavy_control.rb
89
+ HeavyControl.config do
90
+ always_load 'YourContext::YourClass'
91
+ end
92
+ ```
93
+
94
+ You may write several names separated by comma.
95
+
96
+ `always_load` differs from `require_dependency`. It explicitly resolves constant names on initalization via `constantize` (before other constants are loaded). Also it happens each reload in development.
97
+
98
+ It seems to be a bit more accurate way than `require_dependency` because constant resolving involves Rails autoloading mechanism without direct using of more "low-level" `require_dependency`. Also it guarantees that `ignore_subfolder` feature will work as expected.
99
+
100
+ ## Development
101
+
102
+ This gem uses [appraisal](https://github.com/thoughtbot/appraisal) for testing against both 4.2 and 5.0 Rails versions. The command is `bundle exec appraisal rake`.
103
+
104
+ Also code inside your PR should pass [rubocop](https://github.com/bbatsov/rubocop) checks: `bundle exec rake rubocop`.
105
+
106
+ ## Contributing
107
+
108
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ffloyd/heavy_control.
109
+
110
+
111
+ ## License
112
+
113
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'heavy_control'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require 'pry'
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,158 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ heavy_control (0.1.0)
5
+ rails (> 4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.7)
11
+ actionpack (= 4.2.7)
12
+ actionview (= 4.2.7)
13
+ activejob (= 4.2.7)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.7)
17
+ actionview (= 4.2.7)
18
+ activesupport (= 4.2.7)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.7)
24
+ activesupport (= 4.2.7)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.7)
30
+ activesupport (= 4.2.7)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.7)
33
+ activesupport (= 4.2.7)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.7)
36
+ activemodel (= 4.2.7)
37
+ activesupport (= 4.2.7)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.7)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ appraisal (2.1.0)
46
+ bundler
47
+ rake
48
+ thor (>= 0.14.0)
49
+ arel (6.0.3)
50
+ ast (2.3.0)
51
+ builder (3.2.2)
52
+ coderay (1.1.1)
53
+ concurrent-ruby (1.0.2)
54
+ diff-lcs (1.2.5)
55
+ erubis (2.7.0)
56
+ globalid (0.3.7)
57
+ activesupport (>= 4.1.0)
58
+ i18n (0.7.0)
59
+ json (1.8.3)
60
+ loofah (2.0.3)
61
+ nokogiri (>= 1.5.9)
62
+ mail (2.6.4)
63
+ mime-types (>= 1.16, < 4)
64
+ method_source (0.8.2)
65
+ mime-types (3.1)
66
+ mime-types-data (~> 3.2015)
67
+ mime-types-data (3.2016.0521)
68
+ mini_portile2 (2.1.0)
69
+ minitest (5.9.0)
70
+ nokogiri (1.6.8)
71
+ mini_portile2 (~> 2.1.0)
72
+ pkg-config (~> 1.1.7)
73
+ parser (2.3.1.2)
74
+ ast (~> 2.2)
75
+ pkg-config (1.1.7)
76
+ powerpack (0.1.1)
77
+ pry (0.10.4)
78
+ coderay (~> 1.1.0)
79
+ method_source (~> 0.8.1)
80
+ slop (~> 3.4)
81
+ rack (1.6.4)
82
+ rack-test (0.6.3)
83
+ rack (>= 1.0)
84
+ rails (4.2.7)
85
+ actionmailer (= 4.2.7)
86
+ actionpack (= 4.2.7)
87
+ actionview (= 4.2.7)
88
+ activejob (= 4.2.7)
89
+ activemodel (= 4.2.7)
90
+ activerecord (= 4.2.7)
91
+ activesupport (= 4.2.7)
92
+ bundler (>= 1.3.0, < 2.0)
93
+ railties (= 4.2.7)
94
+ sprockets-rails
95
+ rails-deprecated_sanitizer (1.0.3)
96
+ activesupport (>= 4.2.0.alpha)
97
+ rails-dom-testing (1.0.7)
98
+ activesupport (>= 4.2.0.beta, < 5.0)
99
+ nokogiri (~> 1.6.0)
100
+ rails-deprecated_sanitizer (>= 1.0.1)
101
+ rails-html-sanitizer (1.0.3)
102
+ loofah (~> 2.0)
103
+ railties (4.2.7)
104
+ actionpack (= 4.2.7)
105
+ activesupport (= 4.2.7)
106
+ rake (>= 0.8.7)
107
+ thor (>= 0.18.1, < 2.0)
108
+ rainbow (2.1.0)
109
+ rake (10.5.0)
110
+ rspec (3.5.0)
111
+ rspec-core (~> 3.5.0)
112
+ rspec-expectations (~> 3.5.0)
113
+ rspec-mocks (~> 3.5.0)
114
+ rspec-core (3.5.2)
115
+ rspec-support (~> 3.5.0)
116
+ rspec-expectations (3.5.0)
117
+ diff-lcs (>= 1.2.0, < 2.0)
118
+ rspec-support (~> 3.5.0)
119
+ rspec-mocks (3.5.0)
120
+ diff-lcs (>= 1.2.0, < 2.0)
121
+ rspec-support (~> 3.5.0)
122
+ rspec-support (3.5.0)
123
+ rubocop (0.42.0)
124
+ parser (>= 2.3.1.1, < 3.0)
125
+ powerpack (~> 0.1)
126
+ rainbow (>= 1.99.1, < 3.0)
127
+ ruby-progressbar (~> 1.7)
128
+ unicode-display_width (~> 1.0, >= 1.0.1)
129
+ ruby-progressbar (1.8.1)
130
+ slop (3.6.0)
131
+ sprockets (3.7.0)
132
+ concurrent-ruby (~> 1.0)
133
+ rack (> 1, < 3)
134
+ sprockets-rails (3.1.1)
135
+ actionpack (>= 4.0)
136
+ activesupport (>= 4.0)
137
+ sprockets (>= 3.0.0)
138
+ thor (0.19.1)
139
+ thread_safe (0.3.5)
140
+ tzinfo (1.2.2)
141
+ thread_safe (~> 0.1)
142
+ unicode-display_width (1.1.0)
143
+
144
+ PLATFORMS
145
+ ruby
146
+
147
+ DEPENDENCIES
148
+ appraisal
149
+ bundler (~> 1.12)
150
+ heavy_control!
151
+ pry
152
+ rails (~> 4.2)
153
+ rake (~> 10.0)
154
+ rspec (~> 3.0)
155
+ rubocop
156
+
157
+ BUNDLED WITH
158
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,162 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ heavy_control (0.1.0)
5
+ rails (> 4)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.0.0)
11
+ actionpack (= 5.0.0)
12
+ nio4r (~> 1.2)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.0.0)
15
+ actionpack (= 5.0.0)
16
+ actionview (= 5.0.0)
17
+ activejob (= 5.0.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.0.0)
21
+ actionview (= 5.0.0)
22
+ activesupport (= 5.0.0)
23
+ rack (~> 2.0)
24
+ rack-test (~> 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.0.0)
28
+ activesupport (= 5.0.0)
29
+ builder (~> 3.1)
30
+ erubis (~> 2.7.0)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
+ activejob (5.0.0)
34
+ activesupport (= 5.0.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.0.0)
37
+ activesupport (= 5.0.0)
38
+ activerecord (5.0.0)
39
+ activemodel (= 5.0.0)
40
+ activesupport (= 5.0.0)
41
+ arel (~> 7.0)
42
+ activesupport (5.0.0)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ appraisal (2.1.0)
48
+ bundler
49
+ rake
50
+ thor (>= 0.14.0)
51
+ arel (7.1.1)
52
+ ast (2.3.0)
53
+ builder (3.2.2)
54
+ coderay (1.1.1)
55
+ concurrent-ruby (1.0.2)
56
+ diff-lcs (1.2.5)
57
+ erubis (2.7.0)
58
+ globalid (0.3.7)
59
+ activesupport (>= 4.1.0)
60
+ i18n (0.7.0)
61
+ loofah (2.0.3)
62
+ nokogiri (>= 1.5.9)
63
+ mail (2.6.4)
64
+ mime-types (>= 1.16, < 4)
65
+ method_source (0.8.2)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.1.0)
70
+ minitest (5.9.0)
71
+ nio4r (1.2.1)
72
+ nokogiri (1.6.8)
73
+ mini_portile2 (~> 2.1.0)
74
+ pkg-config (~> 1.1.7)
75
+ parser (2.3.1.2)
76
+ ast (~> 2.2)
77
+ pkg-config (1.1.7)
78
+ powerpack (0.1.1)
79
+ pry (0.10.4)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.8.1)
82
+ slop (~> 3.4)
83
+ rack (2.0.1)
84
+ rack-test (0.6.3)
85
+ rack (>= 1.0)
86
+ rails (5.0.0)
87
+ actioncable (= 5.0.0)
88
+ actionmailer (= 5.0.0)
89
+ actionpack (= 5.0.0)
90
+ actionview (= 5.0.0)
91
+ activejob (= 5.0.0)
92
+ activemodel (= 5.0.0)
93
+ activerecord (= 5.0.0)
94
+ activesupport (= 5.0.0)
95
+ bundler (>= 1.3.0, < 2.0)
96
+ railties (= 5.0.0)
97
+ sprockets-rails (>= 2.0.0)
98
+ rails-dom-testing (2.0.1)
99
+ activesupport (>= 4.2.0, < 6.0)
100
+ nokogiri (~> 1.6.0)
101
+ rails-html-sanitizer (1.0.3)
102
+ loofah (~> 2.0)
103
+ railties (5.0.0)
104
+ actionpack (= 5.0.0)
105
+ activesupport (= 5.0.0)
106
+ method_source
107
+ rake (>= 0.8.7)
108
+ thor (>= 0.18.1, < 2.0)
109
+ rainbow (2.1.0)
110
+ rake (10.5.0)
111
+ rspec (3.5.0)
112
+ rspec-core (~> 3.5.0)
113
+ rspec-expectations (~> 3.5.0)
114
+ rspec-mocks (~> 3.5.0)
115
+ rspec-core (3.5.2)
116
+ rspec-support (~> 3.5.0)
117
+ rspec-expectations (3.5.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.5.0)
120
+ rspec-mocks (3.5.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.5.0)
123
+ rspec-support (3.5.0)
124
+ rubocop (0.42.0)
125
+ parser (>= 2.3.1.1, < 3.0)
126
+ powerpack (~> 0.1)
127
+ rainbow (>= 1.99.1, < 3.0)
128
+ ruby-progressbar (~> 1.7)
129
+ unicode-display_width (~> 1.0, >= 1.0.1)
130
+ ruby-progressbar (1.8.1)
131
+ slop (3.6.0)
132
+ sprockets (3.7.0)
133
+ concurrent-ruby (~> 1.0)
134
+ rack (> 1, < 3)
135
+ sprockets-rails (3.1.1)
136
+ actionpack (>= 4.0)
137
+ activesupport (>= 4.0)
138
+ sprockets (>= 3.0.0)
139
+ thor (0.19.1)
140
+ thread_safe (0.3.5)
141
+ tzinfo (1.2.2)
142
+ thread_safe (~> 0.1)
143
+ unicode-display_width (1.1.0)
144
+ websocket-driver (0.6.4)
145
+ websocket-extensions (>= 0.1.0)
146
+ websocket-extensions (0.1.2)
147
+
148
+ PLATFORMS
149
+ ruby
150
+
151
+ DEPENDENCIES
152
+ appraisal
153
+ bundler (~> 1.12)
154
+ heavy_control!
155
+ pry
156
+ rails (~> 5.0)
157
+ rake (~> 10.0)
158
+ rspec (~> 3.0)
159
+ rubocop
160
+
161
+ BUNDLED WITH
162
+ 1.12.5
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'heavy_control/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'heavy_control'
9
+ spec.version = HeavyControl::VERSION
10
+ spec.authors = ['Roman Kolesnev']
11
+ spec.email = ['rvkolesnev@gmail.com']
12
+
13
+ spec.summary = "Take rails constants' loading under control"
14
+ spec.description = "Take rails constants' loading under control"
15
+ spec.homepage = 'https://github.com/ffloyd/heavy_control'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_dependency 'rails', '> 4'
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.12'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'rubocop'
35
+ spec.add_development_dependency 'appraisal'
36
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ module HeavyControl
3
+ module Configurable
4
+ def config(&block)
5
+ reset! unless @config
6
+
7
+ return @config if block.nil?
8
+
9
+ instance_eval(&block)
10
+ end
11
+
12
+ private
13
+
14
+ # DSL methods
15
+
16
+ def reset!
17
+ @config = {
18
+ debug: false,
19
+ ignore_subfolders: [],
20
+ always_load: []
21
+ }
22
+ end
23
+
24
+ def debug(_value = true)
25
+ @config[:debug] = true
26
+ end
27
+
28
+ def ignore_subfolder(subfolder)
29
+ @config[:ignore_subfolders] << subfolder
30
+ end
31
+
32
+ def always_load(*const_names)
33
+ @config[:always_load] += const_names
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module HeavyControl
3
+ module ExplicitLoader
4
+ class << self
5
+ def apply
6
+ load_consts # explicit loading for production
7
+
8
+ ActionDispatch::Reloader.to_prepare do # handle reloading in dev mode
9
+ HeavyControl::ExplicitLoader.load_consts
10
+ end
11
+ end
12
+
13
+ def load_consts
14
+ HeavyControl.config[:always_load].each(&:constantize)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ module HeavyControl
3
+ module Extensions
4
+ module IgnoreSubfolders
5
+ def search_for_file(path_suffix)
6
+ base_result = super(path_suffix)
7
+
8
+ return base_result if base_result
9
+
10
+ HeavyControl.config[:ignore_subfolders].each do |subfolder|
11
+ new_path_suffix = File.join File.split(path_suffix).insert(-2, subfolder)
12
+ result = super(new_path_suffix)
13
+ return result if result
14
+ end
15
+
16
+ nil
17
+ end
18
+
19
+ private
20
+
21
+ def hc_log(msg)
22
+ Rails.logger.debug "HeavyControl: #{msg}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ module HeavyControl
3
+ module Extensions
4
+ module Logging
5
+ def load_missing_constant(from_mod, const_name)
6
+ hc_log "Load missing constant '#{const_name}' from #{from_mod}"
7
+
8
+ super(from_mod, const_name)
9
+ end
10
+
11
+ def require_or_load(file_name, const_path = nil)
12
+ hc_log "Require of load '#{file_name}' with const_path '#{const_path}'"
13
+
14
+ super(file_name, const_path)
15
+ end
16
+
17
+ def search_for_file(path_suffix)
18
+ hc_log "Search for file with suffix '#{path_suffix}'"
19
+
20
+ super(path_suffix).tap do |result|
21
+ hc_log("and found '#{result}'")
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def hc_log(msg)
28
+ Rails.logger.debug "HeavyControl: #{msg}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'extensions/logging'
3
+ require_relative 'extensions/ignore_subfolders'
4
+
5
+ module HeavyControl
6
+ module Extensions
7
+ def self.apply
8
+ ActiveSupport::Dependencies.singleton_class.prepend HeavyControl::Extensions::IgnoreSubfolders
9
+ ActiveSupport::Dependencies.singleton_class.prepend HeavyControl::Extensions::Logging if HeavyControl.config[:debug]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'rails'
3
+
4
+ require 'heavy_control/extensions'
5
+ require 'heavy_control/explicit_loader'
6
+
7
+ module HeavyControl
8
+ class Railtie < Rails::Railtie
9
+ initializer 'heavy_control', after: :load_config_initializers do
10
+ HeavyControl::Extensions.apply
11
+ HeavyControl::ExplicitLoader.apply
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module HeavyControl
3
+ VERSION = '0.1.1'
4
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ require 'heavy_control/version'
3
+ require 'heavy_control/railtie'
4
+ require 'heavy_control/configurable'
5
+
6
+ module HeavyControl
7
+ extend HeavyControl::Configurable
8
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heavy_control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Roman Kolesnev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: appraisal
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Take rails constants' loading under control
112
+ email:
113
+ - rvkolesnev@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
122
+ - Appraisals
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - gemfiles/rails_4.2.gemfile
130
+ - gemfiles/rails_4.2.gemfile.lock
131
+ - gemfiles/rails_5.0.gemfile
132
+ - gemfiles/rails_5.0.gemfile.lock
133
+ - heavy_control.gemspec
134
+ - lib/heavy_control.rb
135
+ - lib/heavy_control/configurable.rb
136
+ - lib/heavy_control/explicit_loader.rb
137
+ - lib/heavy_control/extensions.rb
138
+ - lib/heavy_control/extensions/ignore_subfolders.rb
139
+ - lib/heavy_control/extensions/logging.rb
140
+ - lib/heavy_control/railtie.rb
141
+ - lib/heavy_control/version.rb
142
+ homepage: https://github.com/ffloyd/heavy_control
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ allowed_push_host: https://rubygems.org
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.5.1
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Take rails constants' loading under control
167
+ test_files: []