bound 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +11 -0
- data/bound.gemspec +1 -0
- data/lib/bound.rb +7 -2
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +14 -1
- data/spec/spec_helper.rb +3 -13
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f851ca90e635f3f6ac942e875e89fb87670ec9d
|
4
|
+
data.tar.gz: de5b33718676163ed2d8177b1a7b887b59b33b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f3153699f140a1e55ba3ab153b76a7ad435acc00cc0d2640b958eaf0364f36d24118bd678944e83ccc9cf36aef0172c097602c1ccd0a772ed4708d843f1e691
|
7
|
+
data.tar.gz: 8a4f3c15288c91e8387acf7b87e4ff7ec430d5d70993eccbba3ab605291f74dc69c0ed80dffbe376d3c14f748ba7fd206975447a3ef443c7a495a03b145ad2c1
|
data/Rakefile
CHANGED
data/bound.gemspec
CHANGED
data/lib/bound.rb
CHANGED
@@ -44,11 +44,16 @@ class Bound
|
|
44
44
|
seed
|
45
45
|
end
|
46
46
|
|
47
|
+
def method_missing(meth, *args, &blk)
|
48
|
+
attribute = meth.to_s.gsub(/=$/, '')
|
49
|
+
raise ArgumentError.new("Unknown attribute: #{attribute}")
|
50
|
+
end
|
51
|
+
|
47
52
|
private
|
48
53
|
|
49
54
|
def validate!
|
50
55
|
self.class.attributes.each do |attribute|
|
51
|
-
raise ArgumentError unless @hash.key?(attribute)
|
56
|
+
raise ArgumentError.new("Missing attribute: #{attribute}") unless @hash.key?(attribute)
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
@@ -72,7 +77,7 @@ class Bound
|
|
72
77
|
begin
|
73
78
|
h[attr] = object.public_send(attr)
|
74
79
|
rescue NoMethodError
|
75
|
-
raise ArgumentError.new(attr)
|
80
|
+
raise ArgumentError.new("Missing attribute: #{attr}")
|
76
81
|
end
|
77
82
|
h
|
78
83
|
end
|
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -19,9 +19,11 @@ describe Bound do
|
|
19
19
|
hash.delete :age
|
20
20
|
|
21
21
|
[hash, object].each do |subject|
|
22
|
-
assert_raises ArgumentError, subject.inspect do
|
22
|
+
exception = assert_raises ArgumentError, subject.inspect do
|
23
23
|
User.new(subject)
|
24
24
|
end
|
25
|
+
|
26
|
+
assert_match(/missing.+age/i, exception.message)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -33,6 +35,17 @@ describe Bound do
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
38
|
+
it 'fails if attribute is unknown' do
|
39
|
+
hash[:gender] = "M"
|
40
|
+
subject = hash
|
41
|
+
|
42
|
+
exception = assert_raises ArgumentError, subject.inspect do
|
43
|
+
User.new(subject)
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_match(/unknown.+gender/i, exception.message)
|
47
|
+
end
|
48
|
+
|
36
49
|
describe 'optional attributes' do
|
37
50
|
UserWithoutAge = Bound.new(:name, :optional => [:age])
|
38
51
|
|
data/spec/spec_helper.rb
CHANGED
@@ -14,18 +14,8 @@ require 'bound'
|
|
14
14
|
#
|
15
15
|
class HashObject
|
16
16
|
def self.new(hash)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def self.build_class(attributes)
|
21
|
-
Class.new do
|
22
|
-
attr_accessor(*attributes)
|
23
|
-
|
24
|
-
def initialize(hash)
|
25
|
-
hash.each do |attr, value|
|
26
|
-
public_send "#{attr}=", value
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
17
|
+
attributes = hash.keys
|
18
|
+
values = hash.values
|
19
|
+
Struct.new(*attributes).new(*values)
|
30
20
|
end
|
31
21
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakob Holderbaum
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,20 @@ dependencies:
|
|
39
39
|
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 5.0.7
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 5.0.7
|
42
56
|
description:
|
43
57
|
email:
|
44
58
|
- jh@neopoly.de
|