attr_extras 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/attr_extras.rb +13 -13
- data/lib/attr_extras/version.rb +1 -1
- data/spec/attr_extras_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzZmMWUzNjNiYWMzODYzYzZjODI1YzQwNDljYzliMGE4ZjFkY2IwMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmZhZTI5NDYxMGUyMWRhYjIyYjMzYmFlOGNiYzdhN2EyN2NlZmViZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjhlNTdiMWM1ODJkMWEyNDMyMTNlYjVlMWU2N2U5MjU1ODZiNmViNjg4MDQ4
|
10
|
+
OWFhYTcyYzQ5ZGY1ZWM3OTczYjk3NjM4NDdjZjU2YjU2MjM4MjAzY2I3Mjc2
|
11
|
+
MzcyNWZkZGE5NTE0NDExN2ZlNjc3YTZkYWFmOWZhY2RlMzVhNmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzY4NTk0Y2RkYzAwYzhkMzQ3Njc2NGI3NzYxNGNkYThkOTRjZjU3ODIzNDk2
|
14
|
+
ZTA2NDQ1MGMxZmRjNjNhM2FjNThlNzI4MmE0MjA2ZjQ5YzM0Y2Y2YWQ3NDli
|
15
|
+
ZDM1YTU0OGZmZGRkZmZhZjVhNTgzYjM0ZDE0ODM5OGI4ZTRiODk=
|
data/lib/attr_extras.rb
CHANGED
@@ -4,7 +4,7 @@ require "attr_extras/attr_query"
|
|
4
4
|
require "attr_extras/utils"
|
5
5
|
|
6
6
|
module AttrExtras
|
7
|
-
module
|
7
|
+
module ModuleMethods
|
8
8
|
def attr_initialize(*names)
|
9
9
|
AttrInitialize.new(self, names).apply
|
10
10
|
end
|
@@ -14,6 +14,16 @@ module AttrExtras
|
|
14
14
|
private(*names)
|
15
15
|
end
|
16
16
|
|
17
|
+
def attr_value(*names)
|
18
|
+
attr_reader(*names)
|
19
|
+
|
20
|
+
define_method(:==) do |other|
|
21
|
+
return false unless other.is_a?(self.class)
|
22
|
+
|
23
|
+
names.all? { |attr| self.public_send(attr) == other.public_send(attr) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
17
27
|
def pattr_initialize(*names)
|
18
28
|
attr_initialize(*names)
|
19
29
|
attr_private *Utils.flat_names(names)
|
@@ -24,16 +34,6 @@ module AttrExtras
|
|
24
34
|
attr_value *Utils.flat_names(names)
|
25
35
|
end
|
26
36
|
|
27
|
-
def attr_value(*names)
|
28
|
-
attr_reader *names
|
29
|
-
|
30
|
-
define_method(:==) do |other|
|
31
|
-
return false unless other.is_a?(self.class)
|
32
|
-
|
33
|
-
names.all? { |attr| self.public_send(attr) == other.public_send(attr) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
37
|
def method_object(method_name, *names)
|
38
38
|
singleton_class.send(:define_method, method_name) do |*values|
|
39
39
|
new(*values).send(method_name)
|
@@ -52,6 +52,6 @@ module AttrExtras
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
class
|
56
|
-
include AttrExtras::
|
55
|
+
class Module
|
56
|
+
include AttrExtras::ModuleMethods
|
57
57
|
end
|
data/lib/attr_extras/version.rb
CHANGED
data/spec/attr_extras_spec.rb
CHANGED
@@ -251,3 +251,17 @@ describe Object, ".attr_query" do
|
|
251
251
|
lambda { Object.attr_query(:foo) }.must_raise RuntimeError
|
252
252
|
end
|
253
253
|
end
|
254
|
+
|
255
|
+
describe AttrExtras, "in modules" do
|
256
|
+
it "is supported" do
|
257
|
+
mod = Module.new do
|
258
|
+
pattr_initialize :name
|
259
|
+
end
|
260
|
+
|
261
|
+
klass = Class.new do
|
262
|
+
include mod
|
263
|
+
end
|
264
|
+
|
265
|
+
klass.new("Hello").send(:name).must_equal "Hello"
|
266
|
+
end
|
267
|
+
end
|