attr_extras 5.0.0 → 5.1.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: fd15c690db7cddf4aa28a7bd1c461d01b07883e5
4
- data.tar.gz: 02a2356ba8d7a3ebd8a5dc944a92cd3a337df577
3
+ metadata.gz: e7b11dd2ebaf3539d9762cf9563f38e916a4e034
4
+ data.tar.gz: 3163edce22740e67ff4baf9aa69912b6406bbae1
5
5
  SHA512:
6
- metadata.gz: c7fe4495e99a5bfde538d23bb1d39e48add881babe4da8c9b3d819bb3803db465c7a8452070a4e02c1ca772ac1a8572c1b5b83c36df9ad3bf38dd5b218a5ff6c
7
- data.tar.gz: 0c3f59b421f30e9ac25702851ce9fae3c56f4286b4d9e27fef241a2f0753162bdbd3cb067704999fb28f34e29661c2d62d83293030d57a48664ce834d6b47942
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.
@@ -86,5 +86,9 @@ module AttrExtras
86
86
  def attr_implement(*names)
87
87
  AttrImplement.new(self, names).apply
88
88
  end
89
+
90
+ def cattr_implement(*names)
91
+ AttrImplement.new(self.singleton_class, names).apply
92
+ end
89
93
  end
90
94
  end
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "5.0.0"
2
+ VERSION = "5.1.0"
3
3
  end
@@ -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 "baz"
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.0.0
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-06-28 00:00:00.000000000 Z
13
+ date: 2016-10-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest