dry-types-rails 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17ddc6af375275a3b7a2b8d308aa0d08ed691b3a
4
- data.tar.gz: 1bcc9b89377dc0bfdced5663a4a2294fa7c4a3a9
3
+ metadata.gz: 8f4484674fefa22d0eece7e0979205901c0f8172
4
+ data.tar.gz: 1d56a17806cc8928757798163d36ee57c0617699
5
5
  SHA512:
6
- metadata.gz: ae5f11499e9e9b06abf95059edd7e50bbca4f840cbc721bb845a4bdf5a2ada831ddab177ad1befde3ffafd8f451ed159a290d35322dcf2a04da02ccb88f45df4
7
- data.tar.gz: 71d6cfe25f896dacfcac05f3881faaedb9baaa3112fadc5dfe48bd71c04ebde41946eb61b3cb84dc46140c65c11081ea3c32bfad04f77c3f554e232a86e05406
6
+ metadata.gz: 4b748710cd2edabd5800592606c57b0fee0b4d9d8f9c00e4e618752c001b5f459b58e0007c3a606797bb9bfaec1d8eebf4c51eab5c72265dab58c7a313b93ab3
7
+ data.tar.gz: 817920db298cac92e9b562cc505f457c4f30c4fe0fb2af969f919b6cd2f8fd0855fc0a16549817faa08c886d4f40a6c7b882a8f0bc66386b8ef66e75b1de5abb
data/README.md CHANGED
@@ -2,18 +2,24 @@
2
2
 
3
3
  Really simple gem that will help you work with the [`dry-types`](https://github.com/dryrb/dry-types) gem in development.
4
4
 
5
+ ## Current status: EXPERIMENTAL
6
+
7
+ This gem currently "works for me", but as of right now I'm sure there are a number of edge cases that haven't been hit yet. As those occur, please report them so I can add specs to test them.
8
+
5
9
  ## Raison d'être
6
10
 
7
- Rails reloads code quite often in development, this broke the usage of `Dry::Data` since it would register the same types multiple times and raise exceptions.
11
+ Rails reloads code quite often in development, this broke the usage of `Dry::Types` since it would register the same types multiple times and raise exceptions.
8
12
 
9
13
  ## Installation
10
14
 
11
15
  Add this line to your application's Gemfile:
12
16
 
13
17
  ```ruby
14
- gem 'dry-types-rails'
18
+ gem 'dry-types-rails', group: :development
15
19
  ```
16
20
 
21
+ Note that it should __only__ be included in your development environment.
22
+
17
23
  ## Usage
18
24
 
19
25
  Nothing to do, this is using `Rails::Railtie`, which means it gets loaded automatically.
@@ -26,3 +32,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jerome
26
32
 
27
33
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
28
34
 
35
+ ## Thanks
36
+
37
+ - @AMHOL
38
+ - @jeromegn
39
+ - @pnomolos
@@ -1,13 +1,38 @@
1
1
  module Dry
2
2
  module Types
3
3
  module Rails
4
+ module TypesRegistration
5
+ REGISTERED_TYPES = Concurrent::Array.new
6
+
7
+ def register_class(klass, meth = :new)
8
+ super.tap do
9
+ # Check to see if we need to remove the registered type
10
+ autoloaded = ActiveSupport::Dependencies.will_unload?(klass)
11
+ # ActiveSupport::Dependencies.will_unload?(klass) won't return true yet
12
+ # if it's the first time a constant is being autoloaded
13
+ # so we have to see if we're in the middle of loading a missing constants
14
+ autoloaded |= caller(4).any? { |line| line =~ /\:in.*?new_constants_in/ }
15
+
16
+ REGISTERED_TYPES << klass if autoloaded
17
+ end
18
+ end
19
+ end
20
+
21
+ Dry::Types.module_eval do
22
+ class << self
23
+ prepend(TypesRegistration)
24
+ end
25
+ end
26
+
4
27
  class Railtie < ::Rails::Railtie
5
28
  config.to_prepare do
6
- if Dry::Types.instance_variable_defined? :@container
7
- Dry::Types.remove_instance_variable :@container
29
+ TypesRegistration::REGISTERED_TYPES.each do |type|
30
+ type = Dry::Types.identifier(type)
31
+ Dry::Types.container._container.delete(type)
32
+ Dry::Types.type_map.delete(type)
8
33
  end
9
34
  end
10
35
  end
11
36
  end
12
37
  end
13
- end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module Dry
2
2
  module Types
3
3
  module Rails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-types-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerome Gravel-Niquet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-26 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler