dry-core 0.3.4 → 0.4.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 +4 -4
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/lib/dry/core/class_attributes.rb +36 -14
- data/lib/dry/core/errors.rb +5 -0
- data/lib/dry/core/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: 59a2526ad9fd5d5a7225da0f28423132f7497085
|
4
|
+
data.tar.gz: 2f5b0fc541fbdc6ec2d79f57a80a36a0f900ba26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9beae2da47f5c3189564c7222f6755c175c071f0fe0061ae87e7b89a937129503b557eb952216e2897c1ac5e77741d4b46abbd9d7ab489d9496edf02d4f5e0d4
|
7
|
+
data.tar.gz: 98698a801fc0fef684980f66d58ddb30b242ff3053eb3953f3ad3bfdaffc78546f792d6cc1124031f593bd830d0ab2f729a3729d070275389aae5d152301decb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# v0.4.0 2017-11-02
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Added the `:type` option to class attributes, you can now restrict attribute values with a type. You can either use plain ruby types (`Integer`, `String`, etc) or `dry-types` (GustavoCaso)
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class Foo
|
9
|
+
extend Dry::Core::ClassAttributes
|
10
|
+
|
11
|
+
defines :ruby_attr, type: Integer
|
12
|
+
defines :dry_attr, type: Dry::Types['strict.int']
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
[Compare v0.3.4...v0.4.0](https://github.com/dry-rb/dry-core/compare/v0.3.4...v0.4.0)
|
17
|
+
|
1
18
|
# v0.3.4 2017-09-29
|
2
19
|
|
3
20
|
### Fixed
|
data/Gemfile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'dry/core/constants'
|
2
|
+
require 'dry/core/errors'
|
2
3
|
|
3
4
|
module Dry
|
4
5
|
module Core
|
@@ -11,25 +12,44 @@ module Dry
|
|
11
12
|
# Specify what attributes a class will use
|
12
13
|
#
|
13
14
|
# @example
|
14
|
-
#
|
15
|
-
#
|
15
|
+
# class ExtraClass
|
16
|
+
# extend Dry::Core::ClassAttributes
|
16
17
|
#
|
17
|
-
#
|
18
|
+
# defines :hello
|
18
19
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# end
|
20
|
+
# hello 'world'
|
21
|
+
# end
|
22
22
|
#
|
23
|
-
#
|
24
|
-
# two 'two'
|
25
|
-
# end
|
23
|
+
# @example with inheritance and type checking
|
26
24
|
#
|
27
|
-
#
|
28
|
-
#
|
25
|
+
# class MyClass
|
26
|
+
# extend Dry::Core::ClassAttributes
|
29
27
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
|
28
|
+
# defines :one, :two, type: Integer
|
29
|
+
#
|
30
|
+
# one 1
|
31
|
+
# two 2
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# class OtherClass < MyClass
|
35
|
+
# two 3
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# MyClass.one # => 1
|
39
|
+
# MyClass.two # => 2
|
40
|
+
#
|
41
|
+
# OtherClass.one # => 1
|
42
|
+
# OtherClass.two # => 3
|
43
|
+
#
|
44
|
+
# @example with dry-types
|
45
|
+
#
|
46
|
+
# class Foo
|
47
|
+
# extend Dry::Core::ClassAttributes
|
48
|
+
#
|
49
|
+
# defines :one, :two, type: Dry::Types['strict.int']
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
def defines(*args, type: Object)
|
33
53
|
mod = Module.new do
|
34
54
|
args.each do |name|
|
35
55
|
define_method(name) do |value = Undefined|
|
@@ -42,6 +62,8 @@ module Dry
|
|
42
62
|
nil
|
43
63
|
end
|
44
64
|
else
|
65
|
+
raise InvalidClassAttributeValue unless type === value
|
66
|
+
|
45
67
|
instance_variable_set(ivar, value)
|
46
68
|
end
|
47
69
|
end
|
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.
|
4
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/dry/core/class_builder.rb
|
93
93
|
- lib/dry/core/constants.rb
|
94
94
|
- lib/dry/core/deprecations.rb
|
95
|
+
- lib/dry/core/errors.rb
|
95
96
|
- lib/dry/core/extensions.rb
|
96
97
|
- lib/dry/core/inflector.rb
|
97
98
|
- lib/dry/core/version.rb
|