usable 3.6.1 → 3.6.2
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/CHANGELOG.md +6 -0
- data/README.md +2 -1
- data/lib/usable.rb +18 -1
- data/lib/usable/eager_load.rb +7 -0
- data/lib/usable/railtie.rb +9 -2
- data/lib/usable/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e54cf5fe16514640297183af2af12a092aaf91a6
|
4
|
+
data.tar.gz: f709d8c6daec561b606ab642e87883a83a7d17b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eed3a4121398ecdf306c1bef04d04e9702d0cde1a3f3e34b9895eeaa6d9721d76b0881ec82ff47078d4f8d3edd02936c6d311c0365b6252558e376df9f86e399
|
7
|
+
data.tar.gz: 70c4103c6acdedadf2c8c56ed078bcdf813e4bc33d33dba2aeb2ad5e9ffcad2debea3df677db82071f34a62dfe823e02da7d8d42e97b08a6bc310709c2732378
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -132,7 +132,8 @@ Mixin => MixinUsed
|
|
132
132
|
|
133
133
|
#### __since 3.6__
|
134
134
|
|
135
|
-
Eager-load and freeze usables in production Rails environments with the `frozen` setting
|
135
|
+
Eager-load and freeze usables in production Rails environments with the `frozen` setting. Note that `config.cache_classes`
|
136
|
+
(Rails 3+) or `config.eager_load` (Rails 4+) must also be true, since it hooks into Rails' eager load process.
|
136
137
|
|
137
138
|
```ruby
|
138
139
|
config.usable_config.frozen = true
|
data/lib/usable.rb
CHANGED
@@ -6,15 +6,32 @@ require 'usable/mod_extender'
|
|
6
6
|
require 'usable/config'
|
7
7
|
|
8
8
|
module Usable
|
9
|
+
def self.logger
|
10
|
+
@logger ||= begin
|
11
|
+
require 'logger'
|
12
|
+
Logger.new(STDOUT).tap do |config|
|
13
|
+
config.formatter = proc { |*args| "[#{name}] #{args[0]}: #{args[-1]}\n" }
|
14
|
+
config.level = Logger::ERROR
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.logger=(obj)
|
20
|
+
@logger = obj
|
21
|
+
end
|
22
|
+
|
9
23
|
# Keep track of extended classes and modules so we can freeze all usables on boot in production environments
|
10
24
|
def self.extended_constants
|
11
25
|
@extended_constants ||= Set.new
|
12
26
|
end
|
13
27
|
|
14
28
|
def self.freeze
|
29
|
+
logger.debug { "freezing! #{extended_constants.to_a}" }
|
30
|
+
extended_constants
|
15
31
|
super
|
32
|
+
# This may eager load classes, which is why we freeze ourselves first,
|
33
|
+
# so the +extended+ hook doesn't try to modify @extended_constants while we're iterating over it
|
16
34
|
extended_constants.each { |const| const.usables.freeze }
|
17
|
-
extended_constants.freeze
|
18
35
|
self
|
19
36
|
end
|
20
37
|
|
data/lib/usable/railtie.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
class Usable::Railtie < Rails::Railtie
|
2
2
|
config.usable_config = Struct.new(:frozen).new(false)
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
# This was the only way to consistently hook into the end of the Rails eager load process. The +after_initialize+ hook works great, except when
|
5
|
+
# +Rails.application.eager_load!+ is called directly from a third-party gem (e.g. Resque rake task), in which case the order is not guaranteed.
|
6
|
+
# The solution instead is to overload +eager_load!+
|
7
|
+
initializer 'usable' do |app|
|
8
|
+
if app.config.usable_config.frozen
|
9
|
+
require 'usable/eager_load'
|
10
|
+
app.class.prepend Usable::EagerLoad
|
11
|
+
end
|
5
12
|
end
|
6
13
|
end
|
data/lib/usable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.6.
|
4
|
+
version: 3.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/usable/config.rb
|
82
82
|
- lib/usable/config_multi.rb
|
83
83
|
- lib/usable/config_register.rb
|
84
|
+
- lib/usable/eager_load.rb
|
84
85
|
- lib/usable/mod_extender.rb
|
85
86
|
- lib/usable/railtie.rb
|
86
87
|
- lib/usable/struct.rb
|