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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8f439f8648baa182127cdc634072670fa5651ae4
4
- data.tar.gz: e0b28afc47123a801a92154e1e5616be24962df8
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDkyMTUzNDhkY2Q0NjFiMmQ5ZGNhMWM5MGJkOGNmOWYzMTE4MTkyOA==
5
+ data.tar.gz: !binary |-
6
+ ZTVhMmQ4NDc3YTExMjY1Y2NkYzkzNjk5ZGRmOWM4OTVhMmQwODlkMA==
5
7
  SHA512:
6
- metadata.gz: 641e66f8a897f8a32585674cb30a16c6461e2c5c68d795b2bf79117285078e58656a7be04a77e8c5a1ab112ab57375351221ede2c73e16a50194881d88661894
7
- data.tar.gz: bb9534b45b03c02e410ab8dd6ad3f4b4ac9d1dd7d7913b70ac883e587d2f1db22d46047aad358ebc838135dcee18052f208eec0144fa2663b582f6bdb2bf3a71
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
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "2.2.2"
2
+ VERSION = "2.2.3"
3
3
  end
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
- singleton_class.send(:define_method, method_name) do |*values|
51
- new(*values).send(method_name)
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)
@@ -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 "defines equality based on the attributes" do
15
+ it "does not create writers" do
19
16
  klass = Class.new do
20
- attr_initialize :foo, :bar
21
- attr_value :foo, :bar
17
+ attr_value :foo
22
18
  end
23
19
 
24
- example1 = klass.new("Foo", "Bar")
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
- it "defines equality based on the actual type" do
36
- klass1 = Class.new do
37
- attr_initialize :foo
38
- attr_value :foo
39
- end
40
- klass2 = Class.new do
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
- example1 = klass1.new("Foo")
46
- example2 = klass2.new("Foo")
30
+ example1 = klass.new("Foo", "Bar")
31
+ example2 = klass.new("Foo", "Bar")
32
+ example3 = klass.new("Foo", "Wat")
47
33
 
48
- assert example1 != example2, "Examples should not be equal"
49
- refute example1 == example2, "Examples should not be equal"
50
- end
34
+ assert example1 == example2, "Examples should be equal"
35
+ refute example1 != example2, "Examples should be equal"
51
36
 
52
- it "considers an instance equal to itself" do
53
- klass = Class.new do
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
- instance = klass.new("Foo")
59
-
60
- assert instance == instance, "Instance should be equal to itself"
61
- end
62
-
63
- it "can compare value objects to other kinds of objects" do
64
- klass = Class.new do
65
- attr_initialize :foo
66
- attr_value :foo
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 = klass.new("Foo")
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
- assert instance != "a string"
72
- end
64
+ instance = klass.new("Foo")
73
65
 
74
- it "hashes objects the same if they have the same attributes" do
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
- example1 = klass.new("Foo")
85
- example2 = klass.new("Foo")
86
- example3 = klass.new("Bar")
87
- example4 = klass2.new("Foo")
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
- example1.hash.must_equal example2.hash
90
- example1.hash.wont_equal example3.hash
91
- example1.hash.wont_equal example4.hash
75
+ instance = klass.new("Foo")
92
76
 
93
- assert example1.eql?(example2), "Examples should be 'eql?'"
94
- refute example1.eql?(example3), "Examples should not be 'eql?'"
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
- hash = {}
100
- hash[example1] = :awyeah
101
- hash[example3] = :wat
102
- hash[example4] = :nooooo
103
- hash[example2].must_equal :awyeah
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.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-16 00:00:00.000000000 Z
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
- - ".gitignore"
37
- - ".rvmrc"
38
- - ".travis.yml"
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.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.