bound 0.0.4 → 0.0.5
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 +4 -4
- data/lib/bound.rb +11 -1
- data/lib/bound/version.rb +1 -1
- data/spec/bound_spec.rb +32 -1
- data/spec/spec_helper.rb +5 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c4132942443826a69acf31323e7aa1383e4901
|
4
|
+
data.tar.gz: a227951c47f6e073371f6134f16a193e7f349d49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d06853ef334dcb348d5765d7eb9b47695fd78cfa30a010e3baa5ba311ad61f7b4f6f7a488a4fcdb8b7c68241470bb0203c4ae71185efad1fffbbf19261ca580
|
7
|
+
data.tar.gz: 2a3cabfd7c91b7c127406afe68ba7205421d6e41c6ae8c79bb4af6f65fef651a4386075010cf0011e9bb419160b845bd614c870db3196f65ff448b64b3c57941
|
data/lib/bound.rb
CHANGED
@@ -34,7 +34,7 @@ class Bound
|
|
34
34
|
alias :build :new
|
35
35
|
end
|
36
36
|
|
37
|
-
def initialize(hash_or_object)
|
37
|
+
def initialize(hash_or_object = {})
|
38
38
|
build_hash(hash_or_object)
|
39
39
|
validate!
|
40
40
|
seed
|
@@ -45,6 +45,16 @@ class Bound
|
|
45
45
|
raise ArgumentError.new("Unknown attribute: #{attribute}")
|
46
46
|
end
|
47
47
|
|
48
|
+
def inspect
|
49
|
+
class_name = self.class.name
|
50
|
+
id = '%0#16x' % (object_id << 1)
|
51
|
+
values = (self.class.attributes + self.class.optionals).map do |attr|
|
52
|
+
"#{attr}=#{public_send(attr).inspect}"
|
53
|
+
end
|
54
|
+
|
55
|
+
(["#<#{class_name}:#{id}"] + values + [">"]).join(" ")
|
56
|
+
end
|
57
|
+
|
48
58
|
private
|
49
59
|
|
50
60
|
def validate!
|
data/lib/bound/version.rb
CHANGED
data/spec/bound_spec.rb
CHANGED
@@ -55,6 +55,22 @@ describe Bound do
|
|
55
55
|
assert_match(/unknown.+gender/i, exception.message)
|
56
56
|
end
|
57
57
|
|
58
|
+
describe 'inspect' do
|
59
|
+
let(:inspection) { user.inspect }
|
60
|
+
let(:user) { User.build(hash) }
|
61
|
+
|
62
|
+
it 'lists all attributes' do
|
63
|
+
assert_match(/name="foo"/, inspection)
|
64
|
+
assert_match(/age=23/, inspection)
|
65
|
+
assert_match(/User/, inspection)
|
66
|
+
assert_match(/0x[0-9a-f]{14,}/, inspection)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'does not display @hash' do
|
70
|
+
refute_match(/@hash={.*}/, inspection)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
58
74
|
describe 'optional attributes' do
|
59
75
|
UserWithoutAge = Bound.new(:name).optional(:age)
|
60
76
|
|
@@ -82,4 +98,19 @@ describe Bound do
|
|
82
98
|
end
|
83
99
|
end
|
84
100
|
end
|
85
|
-
|
101
|
+
|
102
|
+
describe 'no attributes' do
|
103
|
+
UserWithoutAttributes = Bound.new
|
104
|
+
let(:hash) { Hash.new }
|
105
|
+
|
106
|
+
it 'works without attributes' do
|
107
|
+
[hash, object, nil].each do |subject|
|
108
|
+
UserWithoutAttributes.build(subject)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'works without argument' do
|
113
|
+
UserWithoutAttributes.build
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.5
|
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-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.0.
|
94
|
+
rubygems_version: 2.0.3
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Implements a nice helper for fast boundary definitions
|