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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e07d85a571ce0e21e25fe723b5ab06b6d97344a0
4
- data.tar.gz: ecc7ccb58e70d4a9d07a5b66055e8b90345e018d
3
+ metadata.gz: 19c4132942443826a69acf31323e7aa1383e4901
4
+ data.tar.gz: a227951c47f6e073371f6134f16a193e7f349d49
5
5
  SHA512:
6
- metadata.gz: 93d3d35a5b23cdcdadb628e3daf2e41fc90cb937c16d4762bd023b0ba4638ce34f35c83fb8a247e0858b5a14c44b737a9b5e8ddf7a07b71f8217a05997126740
7
- data.tar.gz: 3255a3b9c99ef7243decccbd7a27ee80a20bb01bbb3f883396cb45de32fc36ebe764a86f7e993e363bd85080ce2d2a6890478a957591c8eab463b4d2523b6569
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
@@ -1,3 +1,3 @@
1
1
  class Bound
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
- end
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
@@ -16,6 +16,10 @@ class HashObject
16
16
  def self.new(hash)
17
17
  attributes = hash.keys
18
18
  values = hash.values
19
- Struct.new(*attributes).new(*values)
19
+ if attributes.empty?
20
+ Class.new
21
+ else
22
+ Struct.new(*attributes).new(*values)
23
+ end
20
24
  end
21
25
  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
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-20 00:00:00.000000000 Z
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.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