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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjhmZWFmMjMzZDY4YmFmYWYyZDFjYjIyNzU1ZGJlYmFlMmYxNGEwMQ==
4
+ YzZmMWUzNjNiYWMzODYzYzZjODI1YzQwNDljYzliMGE4ZjFkY2IwMw==
5
5
  data.tar.gz: !binary |-
6
- ZTI2NzNiMmEwZDRlNjM3ZjM5ODZiMDcyYTU0YWNmZmE0YTEyODNkOQ==
6
+ ZmZhZTI5NDYxMGUyMWRhYjIyYjMzYmFlOGNiYzdhN2EyN2NlZmViZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzE5YmQ3ZjBmYjY5MzY4OTczY2VkNzNiMDVkNDMxNzUyYmFkMzFlMmJmNTA5
10
- MjYxMjJkZDE1YmJkYzdlNjM2NzIwOWZhMjc2OTUxYjBjNmNjN2RiZDEwODIy
11
- YWVmZGE0MWZjOGY3NWFmNGNkODg5Mzk0NDllMGMzOWJkN2Q3ZGQ=
9
+ YjhlNTdiMWM1ODJkMWEyNDMyMTNlYjVlMWU2N2U5MjU1ODZiNmViNjg4MDQ4
10
+ OWFhYTcyYzQ5ZGY1ZWM3OTczYjk3NjM4NDdjZjU2YjU2MjM4MjAzY2I3Mjc2
11
+ MzcyNWZkZGE5NTE0NDExN2ZlNjc3YTZkYWFmOWZhY2RlMzVhNmQ=
12
12
  data.tar.gz: !binary |-
13
- M2NkMWU1NjAxYTNkMjczY2VkYWEwMDMyODM5OGY0YjcxNDU4YjRlZWRkZmYy
14
- MjZlYzM3NjgyOWVhMjg2NjMyNmJiZTk2OTdlNjk4ODFkZTU4Y2E2ZjFkNWY5
15
- OTgxY2EwYjk0Nzc4MWNmYTc4MTBiZTM0ODQwNzllZTE5ZGY2OGI=
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 ClassMethods
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 Class
56
- include AttrExtras::ClassMethods
55
+ class Module
56
+ include AttrExtras::ModuleMethods
57
57
  end
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -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
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: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh