bound 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bound.gemspec +1 -1
- data/lib/bound.rb +6 -16
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +15 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abad97e3b3b8e96cf9b42a0775bb12fdd347b325
|
4
|
+
data.tar.gz: d8e735b724ae91ba5745d3ee090840f073541c2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d7902861b1dad1ee41a1fa2d7fcc372a0e045bb8da9c55eee63283b415ab049effb939917a16a34e7233addf729216d2cdbf75534c3a41e6deb5e36a5db6a1
|
7
|
+
data.tar.gz: 69eeba09a438642aa2b618055158326d632383c9b825f6bf6d1a744e78af8ea1d95ad7470e75147f6be2acc60ff29ef472534934575a408a2c64340bab313cad
|
data/bound.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Bound::VERSION
|
9
9
|
spec.authors = ["Jakob Holderbaum", "Jan Owiesniak"]
|
10
10
|
spec.email = ["jh@neopoly.de", "jo@neopoly.de"]
|
11
|
-
spec.summary = %q{Implements a nice helper for
|
11
|
+
spec.summary = %q{Implements a nice helper for fast boundary definitions}
|
12
12
|
spec.homepage = ""
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
data/lib/bound.rb
CHANGED
@@ -36,6 +36,8 @@ class Bound
|
|
36
36
|
[]
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
alias :build :new
|
39
41
|
end
|
40
42
|
|
41
43
|
def initialize(hash_or_object)
|
@@ -67,29 +69,17 @@ class Bound
|
|
67
69
|
@hash = hash_or_object
|
68
70
|
else
|
69
71
|
@hash = {}
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def insert_attributes_into_hash(object)
|
76
|
-
self.class.attributes.inject(@hash) do |h, attr|
|
77
|
-
begin
|
78
|
-
h[attr] = object.public_send(attr)
|
79
|
-
rescue NoMethodError
|
80
|
-
raise ArgumentError.new("Missing attribute: #{attr}")
|
81
|
-
end
|
82
|
-
h
|
72
|
+
insert_into_hash(self.class.attributes, hash_or_object)
|
73
|
+
insert_into_hash(self.class.optionals, hash_or_object)
|
83
74
|
end
|
84
75
|
end
|
85
76
|
|
86
|
-
def
|
87
|
-
|
77
|
+
def insert_into_hash(attributes, object)
|
78
|
+
attributes.each_with_object(@hash) do |attr, h|
|
88
79
|
begin
|
89
80
|
h[attr] = object.public_send(attr)
|
90
81
|
rescue NoMethodError
|
91
82
|
end
|
92
|
-
h
|
93
83
|
end
|
94
84
|
end
|
95
85
|
end
|
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -7,6 +7,15 @@ describe Bound do
|
|
7
7
|
let(:hash) { {:name => 'foo', :age => 23} }
|
8
8
|
|
9
9
|
it 'sets all attributes' do
|
10
|
+
[hash, object].each do |subject|
|
11
|
+
user = User.build(subject)
|
12
|
+
|
13
|
+
assert_equal hash[:name], user.name
|
14
|
+
assert_equal hash[:age], user.age
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'also sets all attributes with new instead of build' do
|
10
19
|
[hash, object].each do |subject|
|
11
20
|
user = User.new(subject)
|
12
21
|
|
@@ -20,7 +29,7 @@ describe Bound do
|
|
20
29
|
|
21
30
|
[hash, object].each do |subject|
|
22
31
|
exception = assert_raises ArgumentError, subject.inspect do
|
23
|
-
User.
|
32
|
+
User.build(subject)
|
24
33
|
end
|
25
34
|
|
26
35
|
assert_match(/missing.+age/i, exception.message)
|
@@ -31,7 +40,7 @@ describe Bound do
|
|
31
40
|
hash[:age] = nil
|
32
41
|
|
33
42
|
[hash, object].each do |subject|
|
34
|
-
User.
|
43
|
+
User.build(subject)
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
@@ -40,7 +49,7 @@ describe Bound do
|
|
40
49
|
subject = hash
|
41
50
|
|
42
51
|
exception = assert_raises ArgumentError, subject.inspect do
|
43
|
-
User.
|
52
|
+
User.build(subject)
|
44
53
|
end
|
45
54
|
|
46
55
|
assert_match(/unknown.+gender/i, exception.message)
|
@@ -51,7 +60,7 @@ describe Bound do
|
|
51
60
|
|
52
61
|
it 'sets optional attributes' do
|
53
62
|
[hash, object].each do |subject|
|
54
|
-
user = UserWithoutAge.
|
63
|
+
user = UserWithoutAge.build(subject)
|
55
64
|
|
56
65
|
assert_equal hash[:age], user.age
|
57
66
|
end
|
@@ -61,7 +70,7 @@ describe Bound do
|
|
61
70
|
hash.delete :age
|
62
71
|
|
63
72
|
[hash, object].each do |subject|
|
64
|
-
UserWithoutAge.
|
73
|
+
UserWithoutAge.build(subject)
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
@@ -69,7 +78,7 @@ describe Bound do
|
|
69
78
|
hash[:age] = nil
|
70
79
|
|
71
80
|
[hash, object].each do |subject|
|
72
|
-
UserWithoutAge.
|
81
|
+
UserWithoutAge.build(subject)
|
73
82
|
end
|
74
83
|
end
|
75
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Holderbaum
|
@@ -94,7 +94,7 @@ rubyforge_project:
|
|
94
94
|
rubygems_version: 2.0.0
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
|
-
summary: Implements a nice helper for
|
97
|
+
summary: Implements a nice helper for fast boundary definitions
|
98
98
|
test_files:
|
99
99
|
- spec/bound_spec.rb
|
100
100
|
- spec/spec_helper.rb
|