dry-types-rails 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/dry/types/rails/railtie.rb +28 -3
- data/lib/dry/types/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f4484674fefa22d0eece7e0979205901c0f8172
|
4
|
+
data.tar.gz: 1d56a17806cc8928757798163d36ee57c0617699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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::
|
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
|
-
|
7
|
-
Dry::Types.
|
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
|
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.
|
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-
|
11
|
+
date: 2016-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|