attr_extras 2.2.2 → 2.2.3
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 +13 -5
- data/lib/attr_extras/attr_initialize.rb +1 -1
- data/lib/attr_extras/version.rb +1 -1
- data/lib/attr_extras.rb +2 -2
- data/spec/attr_value_spec.rb +78 -71
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDkyMTUzNDhkY2Q0NjFiMmQ5ZGNhMWM5MGJkOGNmOWYzMTE4MTkyOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTVhMmQ4NDc3YTExMjY1Y2NkYzkzNjk5ZGRmOWM4OTVhMmQwODlkMA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzdkMDZhODUyNzZlZTA5OTYwYjI5NzlhMjUyZTVkMTBlZDgyNGZiNzcyNmU2
|
10
|
+
ZTEwYTRkZTJmZTcyNWYzZWEzMWQyYmZkMzhiZjc5ZTZjMjM4ODM2NjJjODhk
|
11
|
+
OWRkZTUyYjk0Y2M1ZTEzOWMxZjQyMjk2ODA0NjdkMGRiYWQyMzg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTc0YWQ0Y2EwODQwOTczOWMwNGY3MTMxMDE5OWZmYWNkMTgzNDFmYTUxZDA4
|
14
|
+
Y2M1YjU3ZTcwYzkwMmI4NGNiM2ZhNWNiMGY1ODE4ZmEyZWQ4OTE3MWE5OGNj
|
15
|
+
ZGE2ODUyYzM4MTAzMDIwYzVhZmNlYzUzMjJiNjE5Yzg4Yzg4MWI=
|
@@ -38,7 +38,7 @@ class AttrExtras::AttrInitialize
|
|
38
38
|
arity_with_hashes = names.length
|
39
39
|
|
40
40
|
unless (arity_without_hashes..arity_with_hashes).include?(provided_arity)
|
41
|
-
arity_range = [arity_without_hashes, arity_with_hashes].uniq.join("..")
|
41
|
+
arity_range = [ arity_without_hashes, arity_with_hashes ].uniq.join("..")
|
42
42
|
raise ArgumentError, "wrong number of arguments (#{provided_arity} for #{arity_range})"
|
43
43
|
end
|
44
44
|
end
|
data/lib/attr_extras/version.rb
CHANGED
data/lib/attr_extras.rb
CHANGED
@@ -47,8 +47,8 @@ module AttrExtras
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def method_object(method_name, *names)
|
50
|
-
|
51
|
-
new(*values).
|
50
|
+
define_singleton_method(method_name) do |*values|
|
51
|
+
new(*values).public_send(method_name)
|
52
52
|
end
|
53
53
|
|
54
54
|
pattr_initialize(*names)
|
data/spec/attr_value_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require "set"
|
4
1
|
require_relative "spec_helper"
|
2
|
+
require "set"
|
5
3
|
|
6
4
|
describe Object, ".attr_value" do
|
7
5
|
it "creates public readers" do
|
@@ -12,94 +10,103 @@ describe Object, ".attr_value" do
|
|
12
10
|
example = klass.new
|
13
11
|
example.instance_variable_set("@foo", "Foo")
|
14
12
|
example.foo.must_equal "Foo"
|
15
|
-
lambda { example.foo = "new value" }.must_raise NoMethodError
|
16
13
|
end
|
17
14
|
|
18
|
-
it "
|
15
|
+
it "does not create writers" do
|
19
16
|
klass = Class.new do
|
20
|
-
|
21
|
-
attr_value :foo, :bar
|
17
|
+
attr_value :foo
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
example2 = klass.new("Foo", "Bar")
|
26
|
-
example3 = klass.new("Arroz", "Feijão")
|
27
|
-
|
28
|
-
assert example1 == example2, "Examples should be equal"
|
29
|
-
refute example1 != example2, "Examples should be equal"
|
30
|
-
|
31
|
-
refute example1 == example3, "Examples should not be equal"
|
32
|
-
assert example1 != example3, "Examples should not be equal"
|
20
|
+
lambda { klass.new.foo = "new value" }.must_raise NoMethodError
|
33
21
|
end
|
34
22
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
attr_initialize :foo
|
42
|
-
attr_value :foo
|
43
|
-
end
|
23
|
+
describe "object equality" do
|
24
|
+
it "is based on attribute values" do
|
25
|
+
klass = Class.new do
|
26
|
+
attr_initialize :foo, :bar
|
27
|
+
attr_value :foo, :bar
|
28
|
+
end
|
44
29
|
|
45
|
-
|
46
|
-
|
30
|
+
example1 = klass.new("Foo", "Bar")
|
31
|
+
example2 = klass.new("Foo", "Bar")
|
32
|
+
example3 = klass.new("Foo", "Wat")
|
47
33
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
34
|
+
assert example1 == example2, "Examples should be equal"
|
35
|
+
refute example1 != example2, "Examples should be equal"
|
51
36
|
|
52
|
-
|
53
|
-
|
54
|
-
attr_initialize :foo
|
55
|
-
attr_value :foo
|
37
|
+
refute example1 == example3, "Examples should not be equal"
|
38
|
+
assert example1 != example3, "Examples should not be equal"
|
56
39
|
end
|
57
40
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
41
|
+
it "is based on class" do
|
42
|
+
klass1 = Class.new do
|
43
|
+
attr_initialize :foo
|
44
|
+
attr_value :foo
|
45
|
+
end
|
46
|
+
klass2 = Class.new do
|
47
|
+
attr_initialize :foo
|
48
|
+
attr_value :foo
|
49
|
+
end
|
50
|
+
|
51
|
+
example1 = klass1.new("Foo")
|
52
|
+
example2 = klass2.new("Foo")
|
53
|
+
|
54
|
+
assert example1 != example2, "Examples should not be equal"
|
55
|
+
refute example1 == example2, "Examples should not be equal"
|
67
56
|
end
|
68
57
|
|
69
|
-
instance
|
58
|
+
it "considers an instance equal to itself" do
|
59
|
+
klass = Class.new do
|
60
|
+
attr_initialize :foo
|
61
|
+
attr_value :foo
|
62
|
+
end
|
70
63
|
|
71
|
-
|
72
|
-
end
|
64
|
+
instance = klass.new("Foo")
|
73
65
|
|
74
|
-
|
75
|
-
klass = Class.new do
|
76
|
-
attr_initialize :foo
|
77
|
-
attr_value :foo
|
78
|
-
end
|
79
|
-
klass2 = Class.new do
|
80
|
-
attr_initialize :foo
|
81
|
-
attr_value :foo
|
66
|
+
assert instance == instance, "Instance should be equal to itself"
|
82
67
|
end
|
83
68
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
69
|
+
it "can compare value objects to other kinds of objects" do
|
70
|
+
klass = Class.new do
|
71
|
+
attr_initialize :foo
|
72
|
+
attr_value :foo
|
73
|
+
end
|
88
74
|
|
89
|
-
|
90
|
-
example1.hash.wont_equal example3.hash
|
91
|
-
example1.hash.wont_equal example4.hash
|
75
|
+
instance = klass.new("Foo")
|
92
76
|
|
93
|
-
|
94
|
-
|
95
|
-
refute example1.eql?(example4), "Examples should not be 'eql?'"
|
96
|
-
|
97
|
-
Set[example1, example2, example3, example4].length.must_equal 3
|
77
|
+
assert instance != "a string"
|
78
|
+
end
|
98
79
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
80
|
+
it "hashes objects the same if they have the same attributes" do
|
81
|
+
klass1 = Class.new do
|
82
|
+
attr_initialize :foo
|
83
|
+
attr_value :foo
|
84
|
+
end
|
85
|
+
klass2 = Class.new do
|
86
|
+
attr_initialize :foo
|
87
|
+
attr_value :foo
|
88
|
+
end
|
89
|
+
|
90
|
+
klass1_foo = klass1.new("Foo")
|
91
|
+
klass1_foo2 = klass1.new("Foo")
|
92
|
+
klass1_bar = klass1.new("Bar")
|
93
|
+
klass2_foo = klass2.new("Foo")
|
94
|
+
|
95
|
+
klass1_foo.hash.must_equal klass1_foo2.hash
|
96
|
+
klass1_foo.hash.wont_equal klass1_bar.hash
|
97
|
+
klass1_foo.hash.wont_equal klass2_foo.hash
|
98
|
+
|
99
|
+
assert klass1_foo.eql?(klass1_foo2), "Examples should be 'eql?'"
|
100
|
+
refute klass1_foo.eql?(klass1_bar), "Examples should not be 'eql?'"
|
101
|
+
refute klass1_foo.eql?(klass2_foo), "Examples should not be 'eql?'"
|
102
|
+
|
103
|
+
Set[klass1_foo, klass1_foo2, klass1_bar, klass2_foo].length.must_equal 3
|
104
|
+
|
105
|
+
hash = {}
|
106
|
+
hash[klass1_foo] = :awyeah
|
107
|
+
hash[klass1_bar] = :wat
|
108
|
+
hash[klass2_foo] = :nooooo
|
109
|
+
hash[klass1_foo2].must_equal :awyeah
|
110
|
+
end
|
104
111
|
end
|
105
112
|
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.2.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -10,20 +10,20 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ! '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '0'
|
29
29
|
description:
|
@@ -33,9 +33,9 @@ executables: []
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
36
|
+
- .gitignore
|
37
|
+
- .rvmrc
|
38
|
+
- .travis.yml
|
39
39
|
- Gemfile
|
40
40
|
- README.md
|
41
41
|
- Rakefile
|
@@ -66,17 +66,17 @@ require_paths:
|
|
66
66
|
- lib
|
67
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ! '>='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ! '>='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
79
|
+
rubygems_version: 2.2.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Takes some boilerplate out of Ruby with methods like attr_initialize.
|