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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65a97333f23a303a3c720b5273197c5c9233af0a
4
- data.tar.gz: 7338a13fdfeabf4b929d4b3dfcfb7fdd87d1a15e
3
+ metadata.gz: e54cf5fe16514640297183af2af12a092aaf91a6
4
+ data.tar.gz: f709d8c6daec561b606ab642e87883a83a7d17b1
5
5
  SHA512:
6
- metadata.gz: '097a30063e9d48dbf90053e81d7f9617cb019ed3bdae6a93a05bd11f5b2890740042d9c11d19367635e7f3795f3105cbcd2a7a8bd6fdb80aaca9ef5374cb8cca'
7
- data.tar.gz: 6cd0b759bc97a406b5750a39f5d49d5f838f4ed3de190c1d869f578cd97df13e60014016e40980b2e9859e00ee2fa93bc34f3e0f7889d468a5044afc686b88e2
6
+ metadata.gz: eed3a4121398ecdf306c1bef04d04e9702d0cde1a3f3e34b9895eeaa6d9721d76b0881ec82ff47078d4f8d3edd02936c6d311c0365b6252558e376df9f86e399
7
+ data.tar.gz: 70c4103c6acdedadf2c8c56ed078bcdf813e4bc33d33dba2aeb2ad5e9ffcad2debea3df677db82071f34a62dfe823e02da7d8d42e97b08a6bc310709c2732378
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 3.6.2 (1/23/2016)
2
+ =================
3
+
4
+ * Update Railtie to _always_ freeze Usable _after_ `Rails.application.eager_load!`
5
+ * Add `Usable.logger` to help debugging (default level: `Logger::ERROR`)
6
+
1
7
  3.6.1 (1/23/2016)
2
8
  =================
3
9
 
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
 
@@ -0,0 +1,7 @@
1
+ module Usable
2
+ module EagerLoad
3
+ def eager_load!
4
+ super.tap { Usable.freeze unless Usable.frozen? }
5
+ end
6
+ end
7
+ end
@@ -1,6 +1,13 @@
1
1
  class Usable::Railtie < Rails::Railtie
2
2
  config.usable_config = Struct.new(:frozen).new(false)
3
- config.after_initialize do |app|
4
- Usable.freeze if app.config.usable_config.frozen
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
@@ -1,3 +1,3 @@
1
1
  module Usable
2
- VERSION = "3.6.1".freeze
2
+ VERSION = "3.6.2".freeze
3
3
  end
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.1
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-23 00:00:00.000000000 Z
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