dry-core 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aa53a18bd53bba4d61a2fc17d63fc56b36ceb0a
4
- data.tar.gz: f768dafe921caa29c15be6bc7dfa3008f85964c7
3
+ metadata.gz: 59a2526ad9fd5d5a7225da0f28423132f7497085
4
+ data.tar.gz: 2f5b0fc541fbdc6ec2d79f57a80a36a0f900ba26
5
5
  SHA512:
6
- metadata.gz: 1b950916318d30481303d24ec3c2114bf618188d732da41f4e6437ce3b5b11f314263bd6ff84733d6be6121705b701450ef114e7a6c7fa60a0d6a9c55cdd26be
7
- data.tar.gz: 70baf59bb7a1a788c273f92a76c8daa530321c1692ce1bdb515e5b8e84f4b0c8dc444e7140dfc989730f926dc7f14b4727f70b0ac2fb22ab4e2f2dd6eddb63af
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
@@ -8,10 +8,10 @@ group :test do
8
8
  else
9
9
  gem 'activesupport', '~> 4.2'
10
10
  end
11
-
12
11
  gem 'inflecto', '~> 0.0', '>= 0.0.2'
13
12
  gem 'codeclimate-test-reporter', require: false
14
13
  gem 'simplecov', require: false
14
+ gem 'dry-types'
15
15
  end
16
16
 
17
17
  group :tools do
@@ -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
- # class MyClass
15
- # extend Dry::Core::ClassAttributes
15
+ # class ExtraClass
16
+ # extend Dry::Core::ClassAttributes
16
17
  #
17
- # defines :one, :two
18
+ # defines :hello
18
19
  #
19
- # one 1
20
- # two 2
21
- # end
20
+ # hello 'world'
21
+ # end
22
22
  #
23
- # class OtherClass < MyClass
24
- # two 'two'
25
- # end
23
+ # @example with inheritance and type checking
26
24
  #
27
- # MyClass.one # => 1
28
- # MyClass.two # => 2
25
+ # class MyClass
26
+ # extend Dry::Core::ClassAttributes
29
27
  #
30
- # OtherClass.one # => 1
31
- # OtherClass.two # => 'two'
32
- def defines(*args)
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
@@ -0,0 +1,5 @@
1
+ module Dry
2
+ module Core
3
+ InvalidClassAttributeValue = Class.new(StandardError)
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Core
3
- VERSION = '0.3.4'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
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
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-09-29 00:00:00.000000000 Z
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