dry-core 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/CHANGELOG.md +17 -1
- data/lib/dry/core/class_attributes.rb +1 -1
- data/lib/dry/core/class_builder.rb +66 -4
- data/lib/dry/core/deprecations.rb +1 -1
- data/lib/dry/core/extensions.rb +1 -1
- data/lib/dry/core/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: c6b9aba5ba2645ca6591d2977bf2a0935c155b09
|
4
|
+
data.tar.gz: 5df5c9727cc9c1a12c217d159928cafc30dab865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45f58100a89f1132d5f9d0e456e7a498b33ee5545f0688828bae2b13762a8825b013d352f624dd6ba1ae22a15aced47c278dd0242df6cef23eea6bb297aa57f4
|
7
|
+
data.tar.gz: 35233a2424d7ae2672d74707e0f0c1e333fcf5f7a50c61e574965d6c35a78d64d1c2e7b35cc24f51ff02cfe4fb89e2dcc173dff476ae862f4b9bf0fb87ceb90a
|
data/.travis.yml
CHANGED
@@ -9,18 +9,14 @@ script:
|
|
9
9
|
- bundle exec rake
|
10
10
|
rvm:
|
11
11
|
- 2.1.10
|
12
|
-
- 2.2.
|
13
|
-
- 2.3.
|
12
|
+
- 2.2.7
|
13
|
+
- 2.3.4
|
14
14
|
- 2.4.1
|
15
|
-
- jruby-9.1.
|
16
|
-
- rbx-3
|
15
|
+
- jruby-9.1.9.0
|
17
16
|
env:
|
18
17
|
global:
|
19
18
|
- COVERAGE=true
|
20
19
|
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
21
|
-
matrix:
|
22
|
-
allow_failures:
|
23
|
-
- rvm: rbx-3
|
24
20
|
notifications:
|
25
21
|
email: false
|
26
22
|
webhooks:
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,26 @@
|
|
1
|
+
# v0.3.1 to-be-released
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Support for building classes within an existing namespace (flash-gordon)
|
6
|
+
|
7
|
+
[Compare v0.3.0...master](https://github.com/dry-rb/dry-core/compare/v0.3.0...master)
|
8
|
+
|
9
|
+
# v0.3.0 2017-05-05
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
* Class attributes are initialized _before_ running the `inherited` hook. It's slightly more convenient behavior and it's very unlikely anyone will be affected by this, but technically this is a breaking change (flash-gordon)
|
14
|
+
|
15
|
+
[Compare v0.2.4...v0.3.0](https://github.com/dry-rb/dry-core/compare/v0.2.4...v0.3.0)
|
16
|
+
|
1
17
|
# v0.2.4 2017-01-26
|
2
18
|
|
3
19
|
### Fixed
|
4
20
|
|
5
21
|
* Do not require deprecated method to be defined (flash-gordon)
|
6
22
|
|
7
|
-
[Compare v0.2.3...v0.2.4](https://github.com/dry-rb/dry-core/compare/v0.2.
|
23
|
+
[Compare v0.2.3...v0.2.4](https://github.com/dry-rb/dry-core/compare/v0.2.3...v0.2.4)
|
8
24
|
|
9
25
|
# v0.2.3 2016-12-30
|
10
26
|
|
@@ -2,24 +2,52 @@ module Dry
|
|
2
2
|
module Core
|
3
3
|
# Class for generating more classes
|
4
4
|
class ClassBuilder
|
5
|
+
ParentClassMismatch = Class.new(TypeError)
|
6
|
+
|
5
7
|
attr_reader :name
|
6
8
|
attr_reader :parent
|
9
|
+
attr_reader :namespace
|
7
10
|
|
8
|
-
def initialize(name:, parent:
|
11
|
+
def initialize(name:, parent: nil, namespace: nil)
|
9
12
|
@name = name
|
10
|
-
@
|
13
|
+
@namespace = namespace
|
14
|
+
@parent = parent || Object
|
11
15
|
end
|
12
16
|
|
13
17
|
# Generate a class based on options
|
14
18
|
#
|
15
|
-
# @example
|
19
|
+
# @example Create anonymous class
|
16
20
|
# builder = Dry::Core::ClassBuilder.new(name: 'MyClass')
|
17
21
|
#
|
18
22
|
# klass = builder.call
|
19
23
|
# klass.name # => "MyClass"
|
20
24
|
#
|
25
|
+
# @example Create named class
|
26
|
+
# builder = Dry::Core::ClassBuilder.new(name: 'User', namespace: Entities)
|
27
|
+
#
|
28
|
+
# klass = builder.call
|
29
|
+
# klass.name # => "Entities::User"
|
30
|
+
# klass.superclass.name # => "Entities::User"
|
31
|
+
# Entities::User # => "Entities::User"
|
32
|
+
# klass.superclass == Entities::User # => true
|
33
|
+
#
|
21
34
|
# @return [Class]
|
22
35
|
def call
|
36
|
+
klass = if namespace
|
37
|
+
create_named
|
38
|
+
else
|
39
|
+
create_anonymous
|
40
|
+
end
|
41
|
+
|
42
|
+
yield(klass) if block_given?
|
43
|
+
|
44
|
+
klass
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
# @api private
|
50
|
+
def create_anonymous
|
23
51
|
klass = Class.new(parent)
|
24
52
|
name = self.name
|
25
53
|
|
@@ -29,10 +57,44 @@ module Dry
|
|
29
57
|
alias_method :to_s, :name
|
30
58
|
end
|
31
59
|
|
32
|
-
|
60
|
+
klass
|
61
|
+
end
|
62
|
+
|
63
|
+
# @api private
|
64
|
+
def create_named
|
65
|
+
name = self.name
|
66
|
+
base = create_base(namespace, name, parent)
|
67
|
+
klass = Class.new(base)
|
68
|
+
|
69
|
+
namespace.module_eval do
|
70
|
+
remove_const(name)
|
71
|
+
const_set(name, klass)
|
72
|
+
|
73
|
+
const_get(name).name if RUBY_VERSION < '2.4'
|
74
|
+
|
75
|
+
remove_const(name)
|
76
|
+
const_set(name, base)
|
77
|
+
end
|
33
78
|
|
34
79
|
klass
|
35
80
|
end
|
81
|
+
|
82
|
+
# @api private
|
83
|
+
def create_base(namespace, name, parent)
|
84
|
+
if namespace.const_defined?(name, false)
|
85
|
+
existing = namespace.const_get(name)
|
86
|
+
|
87
|
+
unless existing <= parent
|
88
|
+
raise ParentClassMismatch, "#{ existing.name } must be a subclass of #{ parent.name }"
|
89
|
+
end
|
90
|
+
|
91
|
+
existing
|
92
|
+
else
|
93
|
+
klass = Class.new(parent || Object)
|
94
|
+
namespace.const_set(name, klass)
|
95
|
+
klass
|
96
|
+
end
|
97
|
+
end
|
36
98
|
end
|
37
99
|
end
|
38
100
|
end
|
data/lib/dry/core/extensions.rb
CHANGED
data/lib/dry/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|