virtus 1.0.0.beta5 → 1.0.0.beta6
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.
data/README.md
CHANGED
@@ -18,8 +18,8 @@ API](http://rubydoc.info/github/datamapper/dm-core/master/DataMapper/Property)
|
|
18
18
|
with various modifications and improvements. The goal is to provide a common API
|
19
19
|
for defining attributes on a model so all ORMs/ODMs could use it instead of
|
20
20
|
reinventing the wheel all over again. It is also suitable for any other
|
21
|
-
|
22
|
-
data
|
21
|
+
use case where you need to extend your ruby objects with attributes that require
|
22
|
+
data-type coercions.
|
23
23
|
|
24
24
|
Installation
|
25
25
|
------------
|
@@ -39,7 +39,7 @@ Examples
|
|
39
39
|
|
40
40
|
### Using Virtus with Classes
|
41
41
|
|
42
|
-
You can create classes extended with
|
42
|
+
You can create classes extended with Virtus and define attributes:
|
43
43
|
|
44
44
|
``` ruby
|
45
45
|
class User
|
@@ -103,7 +103,7 @@ user.attributes = { :name => 'John' }
|
|
103
103
|
user.attributes
|
104
104
|
# => {:name => 'John'}
|
105
105
|
|
106
|
-
# starting from virtus 1.0.0
|
106
|
+
# starting from virtus 1.0.0 preferred way to do this is to use module builder
|
107
107
|
MyModel = Virtus.model(:constructor => false, :mass_assignment => false)
|
108
108
|
|
109
109
|
class User
|
@@ -113,7 +113,7 @@ end
|
|
113
113
|
|
114
114
|
### Using Virtus with Modules
|
115
115
|
|
116
|
-
You can create modules extended with
|
116
|
+
You can create modules extended with Virtus and define attributes for later
|
117
117
|
inclusion in your classes:
|
118
118
|
|
119
119
|
```ruby
|
@@ -478,9 +478,9 @@ end
|
|
478
478
|
|
479
479
|
## Strict Coercion Mode
|
480
480
|
|
481
|
-
By default
|
481
|
+
By default Virtus returns the input value even when it couldn't coerce it to the expected type.
|
482
482
|
If you want to catch such cases in a noisy way you can use the strict mode in which
|
483
|
-
|
483
|
+
Virtus raises an exception when it failed to coerce an input value.
|
484
484
|
|
485
485
|
``` ruby
|
486
486
|
class User
|
@@ -23,7 +23,7 @@ module Virtus
|
|
23
23
|
# :street => 'Street 1/2', :zipcode => '12345', :city => 'NYC' })
|
24
24
|
#
|
25
25
|
class EmbeddedValue < Attribute
|
26
|
-
TYPES = [Struct, OpenStruct, Virtus].freeze
|
26
|
+
TYPES = [Struct, OpenStruct, Virtus, Model::Constructor].freeze
|
27
27
|
|
28
28
|
class FromStruct < self
|
29
29
|
|
@@ -56,7 +56,7 @@ module Virtus
|
|
56
56
|
|
57
57
|
# @api private
|
58
58
|
def self.determine_type(klass)
|
59
|
-
if klass < Virtus || klass <= OpenStruct
|
59
|
+
if klass < Virtus || klass < Model::Constructor || klass <= OpenStruct
|
60
60
|
FromOpenStruct
|
61
61
|
elsif klass < Struct
|
62
62
|
FromStruct
|
data/lib/virtus/version.rb
CHANGED
@@ -4,13 +4,13 @@ describe 'embedded values' do
|
|
4
4
|
before do
|
5
5
|
module Examples
|
6
6
|
class City
|
7
|
-
include Virtus
|
7
|
+
include Virtus.model
|
8
8
|
|
9
9
|
attribute :name, String
|
10
10
|
end
|
11
11
|
|
12
12
|
class Address
|
13
|
-
include Virtus
|
13
|
+
include Virtus.model
|
14
14
|
|
15
15
|
attribute :street, String
|
16
16
|
attribute :zipcode, String
|
@@ -18,7 +18,7 @@ describe 'embedded values' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class User
|
21
|
-
include Virtus
|
21
|
+
include Virtus.model
|
22
22
|
|
23
23
|
attribute :name, String
|
24
24
|
attribute :address, Address
|
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Virtus::Attribute::EmbeddedValue, '.build' do
|
4
4
|
subject { described_class.build(type) }
|
5
5
|
|
6
|
-
context 'when type is a
|
6
|
+
context 'when type is a Virtus.model' do
|
7
|
+
let(:type) { Class.new { include Virtus.model } }
|
8
|
+
|
9
|
+
it { should be_frozen }
|
10
|
+
|
11
|
+
it { should be_instance_of(Virtus::Attribute::EmbeddedValue::FromOpenStruct) }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when type includes Virtus' do
|
7
15
|
let(:type) { Class.new { include Virtus } }
|
8
16
|
|
9
17
|
it { should be_frozen }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta6
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: descendants_tracker
|