virtus 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -2
- data/Changelog.md +10 -2
- data/Gemfile.devtools +26 -15
- data/README.md +2 -66
- data/lib/virtus/attribute/accessor.rb +11 -0
- data/lib/virtus/attribute_set.rb +2 -2
- data/lib/virtus/instance_methods.rb +1 -1
- data/lib/virtus/support/equalizer.rb +1 -1
- data/lib/virtus/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/virtus/attribute/defined_spec.rb +20 -0
- data/spec/unit/virtus/freeze_spec.rb +13 -0
- data/virtus.gemspec +3 -3
- metadata +24 -13
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install: gem install bundler
|
3
3
|
bundler_args: --without yard guard benchmarks
|
4
|
-
script: "bundle exec rake spec"
|
4
|
+
script: "bundle exec rake metrics:coverage spec:integration"
|
5
5
|
rvm:
|
6
6
|
- 1.9.3
|
7
7
|
- 2.0.0
|
8
|
+
- 2.1.0
|
8
9
|
- jruby-19mode
|
9
|
-
- rbx
|
10
|
+
- rbx
|
10
11
|
- ruby-head
|
11
12
|
matrix:
|
12
13
|
allow_failures:
|
13
14
|
- rvm: ruby-head
|
15
|
+
- rvm: rbx
|
14
16
|
notifications:
|
15
17
|
email:
|
16
18
|
- piotr.solnica@gmail.com
|
data/Changelog.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
# v1.0.
|
1
|
+
# v1.0.2 2014-12-03
|
2
|
+
|
3
|
+
* [improvement] Don’t override already-defined default values when freezing (amarshall)
|
4
|
+
* [improvement] Improved performance of `AttributeSet#each` (Antti)
|
5
|
+
* updated axiom-types dependency to ~> 0.1 (solnic)
|
6
|
+
|
7
|
+
[Compare v1.0.1..v1.0.2](https://github.com/solnic/virtus/compare/v1.0.1...v1.0.2)
|
8
|
+
|
9
|
+
# v1.0.1 2013-12-10
|
2
10
|
|
3
11
|
* [feature] re-introduce `ValueObject#with`, which was removed in the past (senny)
|
4
12
|
* [fixed] strict mode for Boolean type (solnic)
|
5
13
|
|
6
|
-
[Compare v1.0.0..
|
14
|
+
[Compare v1.0.0..v1.0.1](https://github.com/solnic/virtus/compare/v1.0.0...v1.0.1)
|
7
15
|
|
8
16
|
# v1.0.0 2013-10-16
|
9
17
|
|
data/Gemfile.devtools
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem 'rake',
|
5
|
-
gem 'rspec',
|
6
|
-
gem '
|
4
|
+
gem 'rake', '~> 10.1.0'
|
5
|
+
gem 'rspec', '~> 2.14.1'
|
6
|
+
gem 'rspec-core', '~> 2.14.8'
|
7
|
+
gem 'yard', '~> 0.8.7'
|
8
|
+
|
9
|
+
platform :rbx do
|
10
|
+
gem 'rubysl-singleton', '~> 2.0.0'
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
group :yard do
|
10
|
-
gem 'kramdown', '~> 1.2
|
15
|
+
gem 'kramdown', '~> 1.3.2'
|
11
16
|
end
|
12
17
|
|
13
18
|
group :guard do
|
14
|
-
gem 'guard', '~>
|
15
|
-
gem 'guard-bundler', '~>
|
16
|
-
gem 'guard-rspec', '~>
|
17
|
-
gem 'guard-rubocop', '~> 0.2
|
18
|
-
gem 'guard-mutant', '~> 0.0.1'
|
19
|
+
gem 'guard', '~> 2.4.0'
|
20
|
+
gem 'guard-bundler', '~> 2.0.0'
|
21
|
+
gem 'guard-rspec', '~> 4.2.6'
|
22
|
+
gem 'guard-rubocop', '~> 1.0.2'
|
19
23
|
|
20
24
|
# file system change event handling
|
21
|
-
gem 'listen', '~>
|
25
|
+
gem 'listen', '~> 2.5.0'
|
22
26
|
gem 'rb-fchange', '~> 0.0.6', require: false
|
23
27
|
gem 'rb-fsevent', '~> 0.9.3', require: false
|
24
28
|
gem 'rb-inotify', '~> 0.9.0', require: false
|
@@ -30,17 +34,24 @@ group :guard do
|
|
30
34
|
end
|
31
35
|
|
32
36
|
group :metrics do
|
33
|
-
gem 'coveralls', '~> 0.
|
37
|
+
gem 'coveralls', '~> 0.7.0'
|
34
38
|
gem 'flay', '~> 2.4.0'
|
35
|
-
gem 'flog', '~> 4.
|
39
|
+
gem 'flog', '~> 4.2.0'
|
36
40
|
gem 'reek', '~> 1.3.2'
|
37
|
-
gem '
|
38
|
-
gem '
|
39
|
-
gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
|
41
|
+
gem 'simplecov', '~> 0.8.2'
|
42
|
+
gem 'yardstick', '~> 0.9.9'
|
40
43
|
|
41
44
|
platforms :ruby_19, :ruby_20 do
|
42
45
|
gem 'yard-spellcheck', '~> 0.1.5'
|
43
46
|
end
|
47
|
+
|
48
|
+
platform :rbx do
|
49
|
+
gem 'json', '~> 1.8.1'
|
50
|
+
gem 'racc', '~> 1.4'
|
51
|
+
gem 'rubysl-logger', '~> 2.0.0'
|
52
|
+
gem 'rubysl-open-uri', '~> 2.0.0'
|
53
|
+
gem 'rubysl-prettyprint', '~> 2.0.2'
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
group :benchmarks do
|
data/README.md
CHANGED
@@ -6,12 +6,14 @@ Virtus
|
|
6
6
|
[![Dependency Status](https://gemnasium.com/solnic/virtus.png)][gemnasium]
|
7
7
|
[![Code Climate](https://codeclimate.com/github/solnic/virtus.png)][codeclimate]
|
8
8
|
[![Coverage Status](https://coveralls.io/repos/solnic/virtus/badge.png?branch=master)][coveralls]
|
9
|
+
[![Inline docs](http://inch-pages.github.io/github/solnic/virtus.png)][inchpages]
|
9
10
|
|
10
11
|
[gem]: https://rubygems.org/gems/virtus
|
11
12
|
[travis]: https://travis-ci.org/solnic/virtus
|
12
13
|
[gemnasium]: https://gemnasium.com/solnic/virtus
|
13
14
|
[codeclimate]: https://codeclimate.com/github/solnic/virtus
|
14
15
|
[coveralls]: https://coveralls.io/r/solnic/virtus
|
16
|
+
[inchpages]: http://inch-pages.github.io/github/solnic/virtus
|
15
17
|
|
16
18
|
This is a partial extraction of the DataMapper [Property
|
17
19
|
API](http://rubydoc.info/github/datamapper/dm-core/master/DataMapper/Property)
|
@@ -427,48 +429,6 @@ user.set_unique_id('1234-1234')
|
|
427
429
|
user.unique_id # => '1234-1234'
|
428
430
|
```
|
429
431
|
|
430
|
-
Coercions
|
431
|
-
---------
|
432
|
-
|
433
|
-
Virtus uses [Coercible](https://github.com/solnic/coercible) for coercions. This
|
434
|
-
feature is turned on by default. You can turn it off for all attributes like that:
|
435
|
-
|
436
|
-
```ruby
|
437
|
-
# Turn coercions off globally
|
438
|
-
Virtus.coerce(false)
|
439
|
-
|
440
|
-
# ...or you can turn it off for a single attribute
|
441
|
-
class User
|
442
|
-
include Virtus.model
|
443
|
-
|
444
|
-
attribute :name, String, :coerce => false
|
445
|
-
end
|
446
|
-
```
|
447
|
-
|
448
|
-
You can configure coercers too:
|
449
|
-
|
450
|
-
```ruby
|
451
|
-
Virtus.coercer do |config|
|
452
|
-
config.string.boolean_map = { 'yup' => true, 'nope' => false }
|
453
|
-
end
|
454
|
-
|
455
|
-
# Virtus.coercer instance is used by default for all attributes.
|
456
|
-
# You *can* override it for a single attribute if you want:
|
457
|
-
|
458
|
-
my_cool_coercer = Coercible::Coercer.new do |config|
|
459
|
-
# some customization
|
460
|
-
end
|
461
|
-
|
462
|
-
class User
|
463
|
-
include Virtus.model
|
464
|
-
|
465
|
-
attribute :name, String, :coercer => my_cool_coercer
|
466
|
-
end
|
467
|
-
```
|
468
|
-
|
469
|
-
Please check out [Coercible README](https://github.com/solnic/coercible/blob/master/README.md)
|
470
|
-
for more information.
|
471
|
-
|
472
432
|
## Strict Coercion Mode
|
473
433
|
|
474
434
|
By default Virtus returns the input value even when it couldn't coerce it to the expected type.
|
@@ -562,27 +522,3 @@ Contributing
|
|
562
522
|
* Commit, do not mess with Rakefile or version
|
563
523
|
(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)
|
564
524
|
* Send me a pull request. Bonus points for topic branches.
|
565
|
-
|
566
|
-
License
|
567
|
-
-------
|
568
|
-
|
569
|
-
Copyright (c) 2011-2013 Piotr Solnica
|
570
|
-
|
571
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
572
|
-
a copy of this software and associated documentation files (the
|
573
|
-
"Software"), to deal in the Software without restriction, including
|
574
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
575
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
576
|
-
permit persons to whom the Software is furnished to do so, subject to
|
577
|
-
the following conditions:
|
578
|
-
|
579
|
-
The above copyright notice and this permission notice shall be
|
580
|
-
included in all copies or substantial portions of the Software.
|
581
|
-
|
582
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
583
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
584
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
585
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
586
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
587
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
588
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -34,6 +34,17 @@ module Virtus
|
|
34
34
|
descendant.instance_variable_set('@instance_variable_name', "@#{name}")
|
35
35
|
end
|
36
36
|
|
37
|
+
# Return if attribute value is defined
|
38
|
+
#
|
39
|
+
# @param [Object] instance
|
40
|
+
#
|
41
|
+
# @return [Boolean]
|
42
|
+
#
|
43
|
+
# @api public
|
44
|
+
def defined?(instance)
|
45
|
+
instance.instance_variable_defined?(instance_variable_name)
|
46
|
+
end
|
47
|
+
|
37
48
|
# Return value of the attribute
|
38
49
|
#
|
39
50
|
# @param [Object] instance
|
data/lib/virtus/attribute_set.rb
CHANGED
@@ -43,7 +43,7 @@ module Virtus
|
|
43
43
|
# @api public
|
44
44
|
def each
|
45
45
|
return to_enum unless block_given?
|
46
|
-
@index.
|
46
|
+
@index.each { |name, attribute| yield attribute if name.kind_of?(Symbol) }
|
47
47
|
self
|
48
48
|
end
|
49
49
|
|
@@ -209,7 +209,7 @@ module Virtus
|
|
209
209
|
|
210
210
|
# @api private
|
211
211
|
def skip_default?(object, attribute)
|
212
|
-
attribute.lazy? ||
|
212
|
+
attribute.lazy? || attribute.defined?(object)
|
213
213
|
end
|
214
214
|
|
215
215
|
# Merge the attributes into the index
|
data/lib/virtus/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::Attribute, '#defined?' do
|
4
|
+
subject { object.defined?(instance) }
|
5
|
+
|
6
|
+
let(:object) { described_class.build(String, :name => name) }
|
7
|
+
|
8
|
+
let(:model) { Class.new { attr_accessor :test } }
|
9
|
+
let(:name) { :test }
|
10
|
+
let(:instance) { model.new }
|
11
|
+
|
12
|
+
context 'when the attribute value has not been defined' do
|
13
|
+
it { should be(false) }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when the attribute value has been defined' do
|
17
|
+
before { instance.test = nil }
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
end
|
@@ -9,6 +9,7 @@ describe Virtus, '#freeze' do
|
|
9
9
|
|
10
10
|
attribute :name, String, :default => 'foo', :lazy => true
|
11
11
|
attribute :age, Integer, :default => 30
|
12
|
+
attribute :rand, Float, :default => Proc.new { rand }
|
12
13
|
}
|
13
14
|
}
|
14
15
|
|
@@ -18,4 +19,16 @@ describe Virtus, '#freeze' do
|
|
18
19
|
|
19
20
|
its(:name) { should eql('foo') }
|
20
21
|
its(:age) { should be(30) }
|
22
|
+
|
23
|
+
it "does not change dynamic default values" do
|
24
|
+
original_value = object.rand
|
25
|
+
object.freeze
|
26
|
+
expect(object.rand).to eq original_value
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not change default attributes that have been explicitly set" do
|
30
|
+
object.rand = 3.14
|
31
|
+
object.freeze
|
32
|
+
expect(object.rand).to eq 3.14
|
33
|
+
end
|
21
34
|
end
|
data/virtus.gemspec
CHANGED
@@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
18
18
|
gem.extra_rdoc_files = %w[LICENSE README.md TODO.md]
|
19
19
|
|
20
|
-
gem.add_dependency('descendants_tracker', '~> 0.0.
|
21
|
-
gem.add_dependency('equalizer', '~> 0.0.
|
20
|
+
gem.add_dependency('descendants_tracker', '~> 0.0.3')
|
21
|
+
gem.add_dependency('equalizer', '~> 0.0.9')
|
22
22
|
gem.add_dependency('coercible', '~> 1.0')
|
23
|
-
gem.add_dependency('axiom-types', '~> 0.
|
23
|
+
gem.add_dependency('axiom-types', '~> 0.1')
|
24
24
|
end
|
metadata
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Piotr Solnica
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: descendants_tracker
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.0.
|
21
|
+
version: 0.0.3
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.
|
29
|
+
version: 0.0.3
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: equalizer
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
37
|
+
version: 0.0.9
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.
|
45
|
+
version: 0.0.9
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: coercible
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,17 +62,19 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: axiom-types
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
69
|
+
version: '0.1'
|
62
70
|
type: :runtime
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
77
|
+
version: '0.1'
|
69
78
|
description: Attributes on Steroids for Plain Old Ruby Objects
|
70
79
|
email:
|
71
80
|
- piotr.solnica@gmail.com
|
@@ -163,6 +172,7 @@ files:
|
|
163
172
|
- spec/unit/virtus/attribute/collection/class_methods/build_spec.rb
|
164
173
|
- spec/unit/virtus/attribute/collection/coerce_spec.rb
|
165
174
|
- spec/unit/virtus/attribute/custom_collection_spec.rb
|
175
|
+
- spec/unit/virtus/attribute/defined_spec.rb
|
166
176
|
- spec/unit/virtus/attribute/embedded_value/class_methods/build_spec.rb
|
167
177
|
- spec/unit/virtus/attribute/embedded_value/coerce_spec.rb
|
168
178
|
- spec/unit/virtus/attribute/get_spec.rb
|
@@ -199,26 +209,27 @@ files:
|
|
199
209
|
homepage: https://github.com/solnic/virtus
|
200
210
|
licenses:
|
201
211
|
- MIT
|
202
|
-
metadata: {}
|
203
212
|
post_install_message:
|
204
213
|
rdoc_options: []
|
205
214
|
require_paths:
|
206
215
|
- lib
|
207
216
|
required_ruby_version: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
208
218
|
requirements:
|
209
|
-
- - '>='
|
219
|
+
- - ! '>='
|
210
220
|
- !ruby/object:Gem::Version
|
211
221
|
version: '0'
|
212
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
223
|
+
none: false
|
213
224
|
requirements:
|
214
|
-
- - '>='
|
225
|
+
- - ! '>='
|
215
226
|
- !ruby/object:Gem::Version
|
216
227
|
version: '0'
|
217
228
|
requirements: []
|
218
229
|
rubyforge_project:
|
219
|
-
rubygems_version:
|
230
|
+
rubygems_version: 1.8.23
|
220
231
|
signing_key:
|
221
|
-
specification_version:
|
232
|
+
specification_version: 3
|
222
233
|
summary: Attributes on Steroids for Plain Old Ruby Objects
|
223
234
|
test_files: []
|
224
235
|
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 6888ad6cccbdd89e1d41781ceafcc78502aea7d6
|
4
|
-
data.tar.gz: 6638f3068fdee7c541917a7171501a79be0077ea
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: de43cc6cccde89c7009fcb77301e34aa062aea154cfbffc2655efd28d35e41bf0cb0eec547b522cc16861ea66805a7594fa532f2d147366dee5482ae69a9f73f
|
7
|
-
data.tar.gz: 982101e49074af9ce296b4a647e9855e94dd327d7ab35196fb542201d83503b2c2e75e9d4e074e01e5e1565943f26f05b1784c8cca4501d5b638f6ff1992bbe7
|