attr_extras 5.0.0 → 5.1.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/README.md +14 -0
- data/lib/attr_extras/explicit.rb +4 -0
- data/lib/attr_extras/version.rb +1 -1
- data/spec/attr_extras/attr_implement_spec.rb +14 -0
- data/spec/attr_extras/attr_initialize_spec.rb +4 -4
- 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: e7b11dd2ebaf3539d9762cf9563f38e916a4e034
|
4
|
+
data.tar.gz: 3163edce22740e67ff4baf9aa69912b6406bbae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78abb1acb59bc72c5801bbcece4b27669006b2844bd7a461b3ca84359c52a9d7e20f3406cfe26dfb672f703e7867b7b72a19fe81972bcfce88133341b17d34d6
|
7
|
+
data.tar.gz: e6dee11b104ae7f18fb50d5855e49ba5a910d75270d3dd611aaa38210fd5dcae8400ec0654f338b3e2e6f6bdd564c88ca1df66857f5f4717ae592310e4453c71
|
data/README.md
CHANGED
@@ -46,6 +46,7 @@ Also provides conveniences for creating value objects, method objects, query met
|
|
46
46
|
* [`static_facade`](#static_facade)
|
47
47
|
* [`method_object`](#method_object)
|
48
48
|
* [`attr_implement`](#attr_implement)
|
49
|
+
* [`cattr_implement`](#cattr_implement)
|
49
50
|
* [`attr_query`](#attr_query)
|
50
51
|
* [`attr_id_query`](#attr_id_query)
|
51
52
|
|
@@ -326,6 +327,19 @@ end
|
|
326
327
|
```
|
327
328
|
|
328
329
|
|
330
|
+
### `cattr_implement`
|
331
|
+
|
332
|
+
Like [`attr_implement`](#attr_implement) but for class methods.
|
333
|
+
|
334
|
+
Example:
|
335
|
+
|
336
|
+
``` ruby
|
337
|
+
class TransportOrder
|
338
|
+
cattr_implement :must_be_tracked?
|
339
|
+
end
|
340
|
+
```
|
341
|
+
|
342
|
+
|
329
343
|
### `attr_query`
|
330
344
|
|
331
345
|
`attr_query :foo?, :bar?` defines query methods like `foo?`, which is true if (and only if) `foo` is truthy.
|
data/lib/attr_extras/explicit.rb
CHANGED
data/lib/attr_extras/version.rb
CHANGED
@@ -66,3 +66,17 @@ describe Object, ".attr_implement" do
|
|
66
66
|
lambda { klass.new.some_other_method }.must_raise NoMethodError
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe Object, ".cattr_implement" do
|
71
|
+
it "applies to class methods" do
|
72
|
+
klass = Class.new do
|
73
|
+
cattr_implement :foo, [:name, :age]
|
74
|
+
end
|
75
|
+
|
76
|
+
exception = lambda { klass.foo(1, 2) }.must_raise AttrExtras::MethodNotImplementedError
|
77
|
+
exception.message.must_equal "Implement a 'foo(name, age)' method"
|
78
|
+
|
79
|
+
lambda { klass.foo }.must_raise ArgumentError
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -58,14 +58,14 @@ describe Object, ".attr_initialize" do
|
|
58
58
|
|
59
59
|
it "complains about unknown hash values" do
|
60
60
|
klass = Class.new do
|
61
|
-
attr_initialize :foo, [:bar]
|
61
|
+
attr_initialize :foo, [:bar, :baz!]
|
62
62
|
end
|
63
63
|
|
64
64
|
# Should not raise.
|
65
|
-
klass.new("Foo", :bar => "Bar")
|
65
|
+
klass.new("Foo", :bar => "Bar", :baz => "Baz")
|
66
66
|
|
67
|
-
exception = lambda { klass.new("Foo", :bar => "Bar", :baz => "Baz") }.must_raise ArgumentError
|
68
|
-
exception.message.must_include "
|
67
|
+
exception = lambda { klass.new("Foo", :bar => "Bar", :baz => "Baz", :hello => "Hello") }.must_raise ArgumentError
|
68
|
+
exception.message.must_include "[:hello]"
|
69
69
|
end
|
70
70
|
|
71
71
|
it "accepts a block for initialization" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_extras
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-10-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|