virtus 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +18 -0
- data/Changelog.md +9 -2
- data/lib/virtus.rb +1 -1
- data/lib/virtus/attribute/strict.rb +1 -1
- data/lib/virtus/model.rb +1 -1
- data/lib/virtus/value_object.rb +16 -0
- data/lib/virtus/version.rb +1 -1
- data/spec/unit/virtus/attribute/boolean/coerce_spec.rb +43 -0
- data/spec/unit/virtus/value_object_spec.rb +6 -0
- data/virtus.gemspec +1 -1
- metadata +11 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6888ad6cccbdd89e1d41781ceafcc78502aea7d6
|
4
|
+
data.tar.gz: 6638f3068fdee7c541917a7171501a79be0077ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de43cc6cccde89c7009fcb77301e34aa062aea154cfbffc2655efd28d35e41bf0cb0eec547b522cc16861ea66805a7594fa532f2d147366dee5482ae69a9f73f
|
7
|
+
data.tar.gz: 982101e49074af9ce296b4a647e9855e94dd327d7ab35196fb542201d83503b2c2e75e9d4e074e01e5e1565943f26f05b1784c8cca4501d5b638f6ff1992bbe7
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Current project status
|
2
|
+
|
3
|
+
Virtus recently hit it's 1.0 release (2013-10-16). The focus now is on bug-fixes and maintenance while [@solnic][solnic] is away from the project. An experimental branch will be kept up-to date where proposed features and API changes can be made. Please direct your questions and issues to [@elskwid][elskwid], the maintainer.
|
4
|
+
|
5
|
+
# Contributing to Virtus
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
10
|
+
* Commit, do not mess with Rakefile or version
|
11
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
12
|
+
* Send me a pull request. Bonus points for topic branches.
|
13
|
+
|
14
|
+
Author: [@solnic][solnic]
|
15
|
+
Maintainer: [@elskwid][elskwid]
|
16
|
+
|
17
|
+
[solnic]: https://github.com/solnic
|
18
|
+
[elskwid]: https://github.com/elskwid
|
data/Changelog.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
# v1.0.0
|
1
|
+
# v1.0.0 2013-12-10
|
2
|
+
|
3
|
+
* [feature] re-introduce `ValueObject#with`, which was removed in the past (senny)
|
4
|
+
* [fixed] strict mode for Boolean type (solnic)
|
5
|
+
|
6
|
+
[Compare v1.0.0..master](https://github.com/solnic/virtus/compare/v1.0.0...master)
|
7
|
+
|
8
|
+
# v1.0.0 2013-10-16
|
2
9
|
|
3
10
|
This release no longer works with Ruby 1.8.7.
|
4
11
|
|
@@ -24,7 +31,7 @@ This release no longer works with Ruby 1.8.7.
|
|
24
31
|
* [fixed] value object with Hash type works correctly (solnic)
|
25
32
|
* [fixed] issues with value-object subclasses and `#==` method (solnic)
|
26
33
|
|
27
|
-
[Compare v0.5.4..
|
34
|
+
[Compare v0.5.4..v1.0.0](https://github.com/solnic/virtus/compare/v0.5.4...v1.0.0)
|
28
35
|
|
29
36
|
# v0.5.4 2012-12-20
|
30
37
|
|
data/lib/virtus.rb
CHANGED
data/lib/virtus/model.rb
CHANGED
data/lib/virtus/value_object.rb
CHANGED
@@ -62,6 +62,22 @@ module Virtus
|
|
62
62
|
end
|
63
63
|
alias dup clone
|
64
64
|
|
65
|
+
# Create a new ValueObject by combining the passed attribute hash with
|
66
|
+
# the instances attributes.
|
67
|
+
#
|
68
|
+
# @example
|
69
|
+
#
|
70
|
+
# number = PhoneNumber.new(kind: "mobile", number: "123-456-78-90")
|
71
|
+
# number.with(number: "987-654-32-10")
|
72
|
+
# # => #<PhoneNumber kind="mobile" number="987-654-32-10">
|
73
|
+
#
|
74
|
+
# @return [Object]
|
75
|
+
#
|
76
|
+
# @api public
|
77
|
+
def with(attribute_updates)
|
78
|
+
self.class.new(attribute_set.get(self).merge(attribute_updates))
|
79
|
+
end
|
80
|
+
|
65
81
|
end
|
66
82
|
|
67
83
|
module AllowedWriterMethods
|
data/lib/virtus/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::Attribute::Boolean, '#coerce' do
|
4
|
+
subject { object.coerce(input) }
|
5
|
+
|
6
|
+
let(:object) { described_class.build('Boolean', options) }
|
7
|
+
let(:options) { {} }
|
8
|
+
|
9
|
+
context 'when strict is turned off' do
|
10
|
+
context 'with a truthy value' do
|
11
|
+
let(:input) { 1 }
|
12
|
+
|
13
|
+
it { should be(true) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with a falsy value' do
|
17
|
+
let(:input) { 0 }
|
18
|
+
|
19
|
+
it { should be(false) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when strict is turned on' do
|
24
|
+
let(:options) { { :strict => true } }
|
25
|
+
|
26
|
+
context 'with a coercible input' do
|
27
|
+
let(:input) { 1 }
|
28
|
+
|
29
|
+
it { should be(true) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with a non-coercible input' do
|
33
|
+
let(:input) { 'no idea if true or false' }
|
34
|
+
|
35
|
+
it 'raises coercion error' do
|
36
|
+
expect { subject }.to raise_error(
|
37
|
+
Virtus::CoercionError,
|
38
|
+
/Failed to coerce "no idea if true or false"/
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -35,6 +35,12 @@ describe Virtus::ValueObject do
|
|
35
35
|
%(#<Model #{attributes.map { |k, v| "#{k}=#{v.inspect}" }.join(' ')}>)
|
36
36
|
)
|
37
37
|
end
|
38
|
+
|
39
|
+
it 'allows to construct new values using #with' do
|
40
|
+
new_instance = subject.with(:name => "John Doe")
|
41
|
+
expect(new_instance.id).to eql(subject.id)
|
42
|
+
expect(new_instance.name).to eql("John Doe")
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
share_examples_for 'a valid value object with mass-assignment turned on' do
|
data/virtus.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_dependency('descendants_tracker', '~> 0.0.1')
|
21
21
|
gem.add_dependency('equalizer', '~> 0.0.7')
|
22
|
-
gem.add_dependency('coercible', '~> 0
|
22
|
+
gem.add_dependency('coercible', '~> 1.0')
|
23
23
|
gem.add_dependency('axiom-types', '~> 0.0.5')
|
24
24
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Piotr Solnica
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-10
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: descendants_tracker
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: equalizer
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,23 +41,20 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: coercible
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
47
|
+
version: '1.0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
54
|
+
version: '1.0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: axiom-types
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ~>
|
68
60
|
- !ruby/object:Gem::Version
|
@@ -70,7 +62,6 @@ dependencies:
|
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ~>
|
76
67
|
- !ruby/object:Gem::Version
|
@@ -92,6 +83,7 @@ files:
|
|
92
83
|
- .ruby-version
|
93
84
|
- .travis.yml
|
94
85
|
- .yardopts
|
86
|
+
- CONTRIBUTING.md
|
95
87
|
- Changelog.md
|
96
88
|
- Gemfile
|
97
89
|
- Gemfile.devtools
|
@@ -162,6 +154,7 @@ files:
|
|
162
154
|
- spec/shared/idempotent_method_behaviour.rb
|
163
155
|
- spec/shared/options_class_method.rb
|
164
156
|
- spec/spec_helper.rb
|
157
|
+
- spec/unit/virtus/attribute/boolean/coerce_spec.rb
|
165
158
|
- spec/unit/virtus/attribute/boolean/value_coerced_predicate_spec.rb
|
166
159
|
- spec/unit/virtus/attribute/class_methods/build_spec.rb
|
167
160
|
- spec/unit/virtus/attribute/class_methods/coerce_spec.rb
|
@@ -206,27 +199,26 @@ files:
|
|
206
199
|
homepage: https://github.com/solnic/virtus
|
207
200
|
licenses:
|
208
201
|
- MIT
|
202
|
+
metadata: {}
|
209
203
|
post_install_message:
|
210
204
|
rdoc_options: []
|
211
205
|
require_paths:
|
212
206
|
- lib
|
213
207
|
required_ruby_version: !ruby/object:Gem::Requirement
|
214
|
-
none: false
|
215
208
|
requirements:
|
216
|
-
- -
|
209
|
+
- - '>='
|
217
210
|
- !ruby/object:Gem::Version
|
218
211
|
version: '0'
|
219
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
|
-
none: false
|
221
213
|
requirements:
|
222
|
-
- -
|
214
|
+
- - '>='
|
223
215
|
- !ruby/object:Gem::Version
|
224
216
|
version: '0'
|
225
217
|
requirements: []
|
226
218
|
rubyforge_project:
|
227
|
-
rubygems_version:
|
219
|
+
rubygems_version: 2.0.3
|
228
220
|
signing_key:
|
229
|
-
specification_version:
|
221
|
+
specification_version: 4
|
230
222
|
summary: Attributes on Steroids for Plain Old Ruby Objects
|
231
223
|
test_files: []
|
232
224
|
has_rdoc:
|