attribs 1.0.0 → 1.1.0
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/attribs.gemspec +3 -3
- data/lib/attribs/instance_methods.rb +9 -1
- data/spec/attribs_spec.rb +16 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec55d797b8ae1c3b339e09422501c905e9df0728
|
4
|
+
data.tar.gz: 7152836f91cd025073370f106dfe0230b1add314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8cd8ed6aeea533b7a5b1cd9fdc5c9515f32f9f3d012b69d106ff434bd155934b048fc19654dcccb473bcf15aa304cf9e639fcfd80ee07537a44daef0e5624d
|
7
|
+
data.tar.gz: f741038d5e4e786ff6003d90e62559d632b4fadbd5885c3e2f7a2aadfa436c1072c5b268dae830ed1d5cc52e5b84162f75883f15deacf3a3735f36817d0533f5
|
data/attribs.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "attribs"
|
5
|
-
gem.version = "1.
|
5
|
+
gem.version = "1.1.0"
|
6
6
|
gem.authors = ["Arne Brasseur"]
|
7
7
|
gem.email = ["arne@arnebrasseur.net"]
|
8
|
-
gem.summary = %q{
|
9
|
-
gem.description = %q{
|
8
|
+
gem.summary = %q{Easy and flexible Ruby value objects.}
|
9
|
+
gem.description = %q{Easy and flexible Ruby value objects.}
|
10
10
|
gem.homepage = "https://github.com/plexus/attribs"
|
11
11
|
gem.license = "MIT"
|
12
12
|
|
@@ -21,7 +21,15 @@ class Attribs
|
|
21
21
|
|
22
22
|
def pp
|
23
23
|
indent = ->(str) { str.lines.map {|l| " #{l}"}.join }
|
24
|
-
format = ->(val)
|
24
|
+
format = ->(val) do
|
25
|
+
if val.respond_to?(:pp)
|
26
|
+
val.pp
|
27
|
+
elsif val.is_a? Time
|
28
|
+
"Time.parse(\"#{val.inspect}\")"
|
29
|
+
else
|
30
|
+
val.inspect
|
31
|
+
end
|
32
|
+
end
|
25
33
|
|
26
34
|
values = to_h_compact
|
27
35
|
|
data/spec/attribs_spec.rb
CHANGED
@@ -67,7 +67,7 @@ RSpec.describe Attribs do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should expect all attributes' do
|
70
|
-
expect { subject.new(foo: 5) }.to raise_exception
|
70
|
+
expect { subject.new(foo: 5) }.to raise_exception(Anima::Error::Missing)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -99,7 +99,7 @@ RSpec.describe Attribs do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should expect all attributes' do
|
102
|
-
expect { subject.new(foo: 5, bar: 6) }.to raise_exception
|
102
|
+
expect { subject.new(foo: 5, bar: 6) }.to raise_exception(Anima::Error::Missing)
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -113,7 +113,7 @@ RSpec.describe Attribs do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should no longer recognize the old attributes' do
|
116
|
-
expect { subject.new(foo: 3, bar: 3).bar }.to raise_error
|
116
|
+
expect { subject.new(foo: 3, bar: 3).bar }.to raise_error(Anima::Error::Unknown)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -125,7 +125,7 @@ RSpec.describe Attribs do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should no longer recognize the old attributes' do
|
128
|
-
expect { subject.new(foo: 3).foo }.to raise_error
|
128
|
+
expect { subject.new(foo: 3).foo }.to raise_error(Anima::Error::Unknown)
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should keep the defaults' do
|
@@ -150,6 +150,13 @@ RSpec.describe Attribs::InstanceMethods do
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
|
+
let(:one_attr) do
|
154
|
+
Class.new do
|
155
|
+
include Attribs.new(:the_attr)
|
156
|
+
def self.name ; 'OneAttr' ; end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
153
160
|
let(:fixed_width) do
|
154
161
|
Class.new do
|
155
162
|
def initialize(width)
|
@@ -195,6 +202,11 @@ WidgetContainer.new(
|
|
195
202
|
expect(widget.new(color: fixed_width.new(18), size: fixed_width.new(18)).pp).to match /\n/
|
196
203
|
expect(widget.new(color: fixed_width.new(18), size: fixed_width.new(17)).pp).to_not match /\n/
|
197
204
|
end
|
205
|
+
|
206
|
+
it 'should write out a readable representation of Time instanced' do
|
207
|
+
expect(one_attr.new(the_attr: Time.parse("2016-02-22 09:41:29 +1100")).pp)
|
208
|
+
.to eql 'OneAttr.new(the_attr: Time.parse("2016-02-22 09:41:29 +1100"))'
|
209
|
+
end
|
198
210
|
end
|
199
211
|
|
200
212
|
describe '#append_to' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arne Brasseur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anima
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Easy and flexible Ruby value objects.
|
70
70
|
email:
|
71
71
|
- arne@arnebrasseur.net
|
72
72
|
executables: []
|
@@ -105,10 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
107
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.4.
|
108
|
+
rubygems_version: 2.4.5
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
|
-
summary:
|
111
|
+
summary: Easy and flexible Ruby value objects.
|
112
112
|
test_files:
|
113
113
|
- spec/attribs_spec.rb
|
114
114
|
- spec/spec_helper.rb
|