virtus 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -2
- data/.yardopts +1 -0
- data/History.md +51 -0
- data/{README.markdown → README.md} +63 -7
- data/TODO +2 -4
- data/VERSION +1 -1
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/roodi.yml +5 -6
- data/config/site.reek +3 -3
- data/examples/custom_coercion_spec.rb +50 -0
- data/examples/default_values_spec.rb +21 -0
- data/lib/virtus.rb +21 -6
- data/lib/virtus/attribute.rb +113 -253
- data/lib/virtus/attribute/array.rb +6 -3
- data/lib/virtus/attribute/boolean.rb +9 -28
- data/lib/virtus/attribute/date.rb +9 -12
- data/lib/virtus/attribute/date_time.rb +10 -12
- data/lib/virtus/attribute/decimal.rb +4 -11
- data/lib/virtus/attribute/float.rb +4 -11
- data/lib/virtus/attribute/hash.rb +5 -3
- data/lib/virtus/attribute/integer.rb +4 -11
- data/lib/virtus/attribute/numeric.rb +1 -0
- data/lib/virtus/attribute/object.rb +1 -0
- data/lib/virtus/attribute/string.rb +4 -11
- data/lib/virtus/attribute/time.rb +9 -16
- data/lib/virtus/class_methods.rb +42 -7
- data/lib/virtus/coercion.rb +32 -0
- data/lib/virtus/coercion/date.rb +26 -0
- data/lib/virtus/coercion/date_time.rb +26 -0
- data/lib/virtus/coercion/decimal.rb +40 -0
- data/lib/virtus/coercion/false_class.rb +24 -0
- data/lib/virtus/coercion/float.rb +24 -0
- data/lib/virtus/coercion/hash.rb +82 -0
- data/lib/virtus/coercion/integer.rb +60 -0
- data/lib/virtus/coercion/numeric.rb +66 -0
- data/lib/virtus/coercion/object.rb +25 -0
- data/lib/virtus/coercion/string.rb +155 -0
- data/lib/virtus/coercion/symbol.rb +24 -0
- data/lib/virtus/coercion/time.rb +26 -0
- data/lib/virtus/coercion/time_coercions.rb +85 -0
- data/lib/virtus/coercion/true_class.rb +24 -0
- data/lib/virtus/instance_methods.rb +7 -0
- data/lib/virtus/support/descendants_tracker.rb +1 -1
- data/lib/virtus/support/options.rb +114 -0
- data/lib/virtus/support/type_lookup.rb +95 -0
- data/spec/integration/virtus/attributes/attribute/{typecast_spec.rb → set_spec.rb} +7 -7
- data/spec/unit/shared/attribute.rb +3 -3
- data/spec/unit/shared/attribute/accept_options.rb +0 -18
- data/spec/unit/shared/attribute/accepted_options.rb +0 -6
- data/spec/unit/shared/attribute/get.rb +32 -17
- data/spec/unit/shared/attribute/inspect.rb +7 -0
- data/spec/unit/shared/attribute/primitive.rb +15 -0
- data/spec/unit/shared/attribute/set.rb +16 -21
- data/spec/unit/virtus/attribute/array_spec.rb +18 -3
- data/spec/unit/virtus/attribute/boolean_spec.rb +8 -6
- data/spec/unit/virtus/attribute/date_spec.rb +8 -6
- data/spec/unit/virtus/attribute/date_time_spec.rb +8 -6
- data/spec/unit/virtus/attribute/decimal_spec.rb +18 -6
- data/spec/unit/virtus/attribute/float_spec.rb +19 -7
- data/spec/unit/virtus/attribute/hash_spec.rb +5 -3
- data/spec/unit/virtus/attribute/integer_spec.rb +10 -8
- data/spec/unit/virtus/attribute/string_spec.rb +10 -8
- data/spec/unit/virtus/attribute/time_spec.rb +8 -6
- data/spec/unit/virtus/class_methods/attributes_spec.rb +11 -0
- data/spec/unit/virtus/coercion/class_name_reference_spec.rb +17 -0
- data/spec/unit/virtus/coercion/date/class_methods/to_datetime_spec.rb +30 -0
- data/spec/unit/virtus/coercion/date/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/date/class_methods/to_time_spec.rb +12 -0
- data/spec/unit/virtus/coercion/date_time/class_methods/to_date_spec.rb +30 -0
- data/spec/unit/virtus/coercion/date_time/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/date_time/class_methods/to_time_spec.rb +30 -0
- data/spec/unit/virtus/coercion/decimal/class_methods/to_float_spec.rb +12 -0
- data/spec/unit/virtus/coercion/decimal/class_methods/to_integer_spec.rb +12 -0
- data/spec/unit/virtus/coercion/decimal/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/false_class/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/float/class_methods/to_decimal_spec.rb +12 -0
- data/spec/unit/virtus/coercion/float/class_methods/to_integer_spec.rb +12 -0
- data/spec/unit/virtus/coercion/float/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/hash/class_methods/to_array_spec.rb +12 -0
- data/spec/unit/virtus/coercion/hash/class_methods/to_date_spec.rb +31 -0
- data/spec/unit/virtus/coercion/hash/class_methods/to_datetime_spec.rb +31 -0
- data/spec/unit/virtus/coercion/hash/class_methods/to_time_spec.rb +31 -0
- data/spec/unit/virtus/coercion/integer/class_methods/to_boolean_spec.rb +25 -0
- data/spec/unit/virtus/coercion/integer/class_methods/to_decimal_spec.rb +12 -0
- data/spec/unit/virtus/coercion/integer/class_methods/to_float_spec.rb +12 -0
- data/spec/unit/virtus/coercion/integer/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/object/class_methods/method_missing_spec.rb +33 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_boolean_spec.rb +29 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_date_spec.rb +23 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_datetime_spec.rb +50 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb +23 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb +21 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_integer_spec.rb +21 -0
- data/spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb +50 -0
- data/spec/unit/virtus/coercion/symbol/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/coercion/true_class/class_methods/to_string_spec.rb +12 -0
- data/spec/unit/virtus/instance_methods/attributes_spec.rb +7 -0
- data/spec/unit/virtus/options/accept_options_spec.rb +38 -0
- data/spec/unit/virtus/options/accepted_options_spec.rb +21 -0
- data/spec/unit/virtus/options/options_spec.rb +11 -0
- data/spec/unit/virtus/type_lookup/determine_type_spec.rb +68 -0
- data/spec/unit/virtus/type_lookup/primitive_spec.rb +9 -0
- data/virtus.gemspec +70 -17
- metadata +78 -27
- data/History.txt +0 -38
- data/lib/virtus/typecast/boolean.rb +0 -29
- data/lib/virtus/typecast/numeric.rb +0 -87
- data/lib/virtus/typecast/string.rb +0 -24
- data/lib/virtus/typecast/time.rb +0 -192
- data/spec/unit/shared/attribute/complex.rb +0 -15
- data/spec/unit/shared/attribute/options.rb +0 -7
- data/spec/unit/virtus/attribute/attribute_spec.rb +0 -12
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Virtus::TypeLookup, '#primitive' do
|
4
|
+
subject { object.primitive }
|
5
|
+
|
6
|
+
let(:object) { Class.new { extend Virtus::TypeLookup } }
|
7
|
+
|
8
|
+
specify { expect { subject }.to raise_error(NotImplementedError, "#{object}.primitive must be implemented") }
|
9
|
+
end
|
data/virtus.gemspec
CHANGED
@@ -5,25 +5,26 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{virtus}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-07-
|
11
|
+
s.authors = [%q{Piotr Solnica}]
|
12
|
+
s.date = %q{2011-07-30}
|
13
13
|
s.description = %q{Attributes for your plain ruby objects}
|
14
|
-
s.email = [
|
14
|
+
s.email = [%q{piotr@rubyverse.com}]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
|
-
"README.
|
17
|
+
"README.md",
|
18
18
|
"TODO"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
21
|
".rvmrc",
|
22
22
|
".travis.yml",
|
23
|
+
".yardopts",
|
23
24
|
"Gemfile",
|
24
|
-
"History.
|
25
|
+
"History.md",
|
25
26
|
"LICENSE",
|
26
|
-
"README.
|
27
|
+
"README.md",
|
27
28
|
"Rakefile",
|
28
29
|
"TODO",
|
29
30
|
"VERSION",
|
@@ -32,6 +33,8 @@ Gem::Specification.new do |s|
|
|
32
33
|
"config/roodi.yml",
|
33
34
|
"config/site.reek",
|
34
35
|
"config/yardstick.yml",
|
36
|
+
"examples/custom_coercion_spec.rb",
|
37
|
+
"examples/default_values_spec.rb",
|
35
38
|
"lib/virtus.rb",
|
36
39
|
"lib/virtus/attribute.rb",
|
37
40
|
"lib/virtus/attribute/array.rb",
|
@@ -48,13 +51,26 @@ Gem::Specification.new do |s|
|
|
48
51
|
"lib/virtus/attribute/time.rb",
|
49
52
|
"lib/virtus/attribute_set.rb",
|
50
53
|
"lib/virtus/class_methods.rb",
|
54
|
+
"lib/virtus/coercion.rb",
|
55
|
+
"lib/virtus/coercion/date.rb",
|
56
|
+
"lib/virtus/coercion/date_time.rb",
|
57
|
+
"lib/virtus/coercion/decimal.rb",
|
58
|
+
"lib/virtus/coercion/false_class.rb",
|
59
|
+
"lib/virtus/coercion/float.rb",
|
60
|
+
"lib/virtus/coercion/hash.rb",
|
61
|
+
"lib/virtus/coercion/integer.rb",
|
62
|
+
"lib/virtus/coercion/numeric.rb",
|
63
|
+
"lib/virtus/coercion/object.rb",
|
64
|
+
"lib/virtus/coercion/string.rb",
|
65
|
+
"lib/virtus/coercion/symbol.rb",
|
66
|
+
"lib/virtus/coercion/time.rb",
|
67
|
+
"lib/virtus/coercion/time_coercions.rb",
|
68
|
+
"lib/virtus/coercion/true_class.rb",
|
51
69
|
"lib/virtus/instance_methods.rb",
|
52
70
|
"lib/virtus/support/descendants_tracker.rb",
|
53
|
-
"lib/virtus/
|
54
|
-
"lib/virtus/
|
55
|
-
"
|
56
|
-
"lib/virtus/typecast/time.rb",
|
57
|
-
"spec/integration/virtus/attributes/attribute/typecast_spec.rb",
|
71
|
+
"lib/virtus/support/options.rb",
|
72
|
+
"lib/virtus/support/type_lookup.rb",
|
73
|
+
"spec/integration/virtus/attributes/attribute/set_spec.rb",
|
58
74
|
"spec/integration/virtus/class_methods/attribute_spec.rb",
|
59
75
|
"spec/integration/virtus/class_methods/attributes_spec.rb",
|
60
76
|
"spec/integration/virtus/class_methods/const_missing_spec.rb",
|
@@ -64,12 +80,11 @@ Gem::Specification.new do |s|
|
|
64
80
|
"spec/unit/shared/attribute.rb",
|
65
81
|
"spec/unit/shared/attribute/accept_options.rb",
|
66
82
|
"spec/unit/shared/attribute/accepted_options.rb",
|
67
|
-
"spec/unit/shared/attribute/complex.rb",
|
68
83
|
"spec/unit/shared/attribute/get.rb",
|
69
|
-
"spec/unit/shared/attribute/
|
84
|
+
"spec/unit/shared/attribute/inspect.rb",
|
85
|
+
"spec/unit/shared/attribute/primitive.rb",
|
70
86
|
"spec/unit/shared/attribute/set.rb",
|
71
87
|
"spec/unit/virtus/attribute/array_spec.rb",
|
72
|
-
"spec/unit/virtus/attribute/attribute_spec.rb",
|
73
88
|
"spec/unit/virtus/attribute/boolean_spec.rb",
|
74
89
|
"spec/unit/virtus/attribute/class_methods/determine_type_spec.rb",
|
75
90
|
"spec/unit/virtus/attribute/date_spec.rb",
|
@@ -90,12 +105,50 @@ Gem::Specification.new do |s|
|
|
90
105
|
"spec/unit/virtus/attribute_set/parent_spec.rb",
|
91
106
|
"spec/unit/virtus/attribute_set/reset_spec.rb",
|
92
107
|
"spec/unit/virtus/class_methods/attribute_spec.rb",
|
108
|
+
"spec/unit/virtus/class_methods/attributes_spec.rb",
|
93
109
|
"spec/unit/virtus/class_methods/new_spec.rb",
|
110
|
+
"spec/unit/virtus/coercion/class_name_reference_spec.rb",
|
111
|
+
"spec/unit/virtus/coercion/date/class_methods/to_datetime_spec.rb",
|
112
|
+
"spec/unit/virtus/coercion/date/class_methods/to_string_spec.rb",
|
113
|
+
"spec/unit/virtus/coercion/date/class_methods/to_time_spec.rb",
|
114
|
+
"spec/unit/virtus/coercion/date_time/class_methods/to_date_spec.rb",
|
115
|
+
"spec/unit/virtus/coercion/date_time/class_methods/to_string_spec.rb",
|
116
|
+
"spec/unit/virtus/coercion/date_time/class_methods/to_time_spec.rb",
|
117
|
+
"spec/unit/virtus/coercion/decimal/class_methods/to_float_spec.rb",
|
118
|
+
"spec/unit/virtus/coercion/decimal/class_methods/to_integer_spec.rb",
|
119
|
+
"spec/unit/virtus/coercion/decimal/class_methods/to_string_spec.rb",
|
120
|
+
"spec/unit/virtus/coercion/false_class/class_methods/to_string_spec.rb",
|
121
|
+
"spec/unit/virtus/coercion/float/class_methods/to_decimal_spec.rb",
|
122
|
+
"spec/unit/virtus/coercion/float/class_methods/to_integer_spec.rb",
|
123
|
+
"spec/unit/virtus/coercion/float/class_methods/to_string_spec.rb",
|
124
|
+
"spec/unit/virtus/coercion/hash/class_methods/to_array_spec.rb",
|
125
|
+
"spec/unit/virtus/coercion/hash/class_methods/to_date_spec.rb",
|
126
|
+
"spec/unit/virtus/coercion/hash/class_methods/to_datetime_spec.rb",
|
127
|
+
"spec/unit/virtus/coercion/hash/class_methods/to_time_spec.rb",
|
128
|
+
"spec/unit/virtus/coercion/integer/class_methods/to_boolean_spec.rb",
|
129
|
+
"spec/unit/virtus/coercion/integer/class_methods/to_decimal_spec.rb",
|
130
|
+
"spec/unit/virtus/coercion/integer/class_methods/to_float_spec.rb",
|
131
|
+
"spec/unit/virtus/coercion/integer/class_methods/to_string_spec.rb",
|
132
|
+
"spec/unit/virtus/coercion/object/class_methods/method_missing_spec.rb",
|
133
|
+
"spec/unit/virtus/coercion/string/class_methods/to_boolean_spec.rb",
|
134
|
+
"spec/unit/virtus/coercion/string/class_methods/to_date_spec.rb",
|
135
|
+
"spec/unit/virtus/coercion/string/class_methods/to_datetime_spec.rb",
|
136
|
+
"spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb",
|
137
|
+
"spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb",
|
138
|
+
"spec/unit/virtus/coercion/string/class_methods/to_integer_spec.rb",
|
139
|
+
"spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb",
|
140
|
+
"spec/unit/virtus/coercion/symbol/class_methods/to_string_spec.rb",
|
141
|
+
"spec/unit/virtus/coercion/true_class/class_methods/to_string_spec.rb",
|
94
142
|
"spec/unit/virtus/descendants_tracker/add_descendant_spec.rb",
|
95
143
|
"spec/unit/virtus/descendants_tracker/descendants_spec.rb",
|
96
144
|
"spec/unit/virtus/instance_methods/attributes_spec.rb",
|
97
145
|
"spec/unit/virtus/instance_methods/element_reference_spec.rb",
|
98
146
|
"spec/unit/virtus/instance_methods/element_set_spec.rb",
|
147
|
+
"spec/unit/virtus/options/accept_options_spec.rb",
|
148
|
+
"spec/unit/virtus/options/accepted_options_spec.rb",
|
149
|
+
"spec/unit/virtus/options/options_spec.rb",
|
150
|
+
"spec/unit/virtus/type_lookup/determine_type_spec.rb",
|
151
|
+
"spec/unit/virtus/type_lookup/primitive_spec.rb",
|
99
152
|
"tasks/metrics/ci.rake",
|
100
153
|
"tasks/metrics/flay.rake",
|
101
154
|
"tasks/metrics/flog.rake",
|
@@ -109,8 +162,8 @@ Gem::Specification.new do |s|
|
|
109
162
|
"virtus.gemspec"
|
110
163
|
]
|
111
164
|
s.homepage = %q{https://github.com/solnic/virtus}
|
112
|
-
s.require_paths = [
|
113
|
-
s.rubygems_version = %q{1.6
|
165
|
+
s.require_paths = [%q{lib}]
|
166
|
+
s.rubygems_version = %q{1.8.6}
|
114
167
|
s.summary = %q{Attributes for your plain ruby objects}
|
115
168
|
|
116
169
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Piotr Solnica
|
@@ -15,12 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-07-30 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
21
|
+
name: backports
|
22
22
|
prerelease: false
|
23
|
-
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
26
|
- - ~>
|
@@ -32,11 +32,11 @@ dependencies:
|
|
32
32
|
- 0
|
33
33
|
version: 2.3.0
|
34
34
|
type: :development
|
35
|
-
|
36
|
-
version_requirements: *id001
|
35
|
+
requirement: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
38
|
prerelease: false
|
39
|
-
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -48,11 +48,11 @@ dependencies:
|
|
48
48
|
- 4
|
49
49
|
version: 1.6.4
|
50
50
|
type: :development
|
51
|
-
|
52
|
-
version_requirements: *id002
|
51
|
+
requirement: *id002
|
53
52
|
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec
|
54
54
|
prerelease: false
|
55
|
-
|
55
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|
58
58
|
- - ~>
|
@@ -64,8 +64,7 @@ dependencies:
|
|
64
64
|
- 0
|
65
65
|
version: 2.6.0
|
66
66
|
type: :development
|
67
|
-
|
68
|
-
version_requirements: *id003
|
67
|
+
requirement: *id003
|
69
68
|
description: Attributes for your plain ruby objects
|
70
69
|
email:
|
71
70
|
- piotr@rubyverse.com
|
@@ -75,15 +74,16 @@ extensions: []
|
|
75
74
|
|
76
75
|
extra_rdoc_files:
|
77
76
|
- LICENSE
|
78
|
-
- README.
|
77
|
+
- README.md
|
79
78
|
- TODO
|
80
79
|
files:
|
81
80
|
- .rvmrc
|
82
81
|
- .travis.yml
|
82
|
+
- .yardopts
|
83
83
|
- Gemfile
|
84
|
-
- History.
|
84
|
+
- History.md
|
85
85
|
- LICENSE
|
86
|
-
- README.
|
86
|
+
- README.md
|
87
87
|
- Rakefile
|
88
88
|
- TODO
|
89
89
|
- VERSION
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- config/roodi.yml
|
93
93
|
- config/site.reek
|
94
94
|
- config/yardstick.yml
|
95
|
+
- examples/custom_coercion_spec.rb
|
96
|
+
- examples/default_values_spec.rb
|
95
97
|
- lib/virtus.rb
|
96
98
|
- lib/virtus/attribute.rb
|
97
99
|
- lib/virtus/attribute/array.rb
|
@@ -108,13 +110,26 @@ files:
|
|
108
110
|
- lib/virtus/attribute/time.rb
|
109
111
|
- lib/virtus/attribute_set.rb
|
110
112
|
- lib/virtus/class_methods.rb
|
113
|
+
- lib/virtus/coercion.rb
|
114
|
+
- lib/virtus/coercion/date.rb
|
115
|
+
- lib/virtus/coercion/date_time.rb
|
116
|
+
- lib/virtus/coercion/decimal.rb
|
117
|
+
- lib/virtus/coercion/false_class.rb
|
118
|
+
- lib/virtus/coercion/float.rb
|
119
|
+
- lib/virtus/coercion/hash.rb
|
120
|
+
- lib/virtus/coercion/integer.rb
|
121
|
+
- lib/virtus/coercion/numeric.rb
|
122
|
+
- lib/virtus/coercion/object.rb
|
123
|
+
- lib/virtus/coercion/string.rb
|
124
|
+
- lib/virtus/coercion/symbol.rb
|
125
|
+
- lib/virtus/coercion/time.rb
|
126
|
+
- lib/virtus/coercion/time_coercions.rb
|
127
|
+
- lib/virtus/coercion/true_class.rb
|
111
128
|
- lib/virtus/instance_methods.rb
|
112
129
|
- lib/virtus/support/descendants_tracker.rb
|
113
|
-
- lib/virtus/
|
114
|
-
- lib/virtus/
|
115
|
-
-
|
116
|
-
- lib/virtus/typecast/time.rb
|
117
|
-
- spec/integration/virtus/attributes/attribute/typecast_spec.rb
|
130
|
+
- lib/virtus/support/options.rb
|
131
|
+
- lib/virtus/support/type_lookup.rb
|
132
|
+
- spec/integration/virtus/attributes/attribute/set_spec.rb
|
118
133
|
- spec/integration/virtus/class_methods/attribute_spec.rb
|
119
134
|
- spec/integration/virtus/class_methods/attributes_spec.rb
|
120
135
|
- spec/integration/virtus/class_methods/const_missing_spec.rb
|
@@ -124,12 +139,11 @@ files:
|
|
124
139
|
- spec/unit/shared/attribute.rb
|
125
140
|
- spec/unit/shared/attribute/accept_options.rb
|
126
141
|
- spec/unit/shared/attribute/accepted_options.rb
|
127
|
-
- spec/unit/shared/attribute/complex.rb
|
128
142
|
- spec/unit/shared/attribute/get.rb
|
129
|
-
- spec/unit/shared/attribute/
|
143
|
+
- spec/unit/shared/attribute/inspect.rb
|
144
|
+
- spec/unit/shared/attribute/primitive.rb
|
130
145
|
- spec/unit/shared/attribute/set.rb
|
131
146
|
- spec/unit/virtus/attribute/array_spec.rb
|
132
|
-
- spec/unit/virtus/attribute/attribute_spec.rb
|
133
147
|
- spec/unit/virtus/attribute/boolean_spec.rb
|
134
148
|
- spec/unit/virtus/attribute/class_methods/determine_type_spec.rb
|
135
149
|
- spec/unit/virtus/attribute/date_spec.rb
|
@@ -150,12 +164,50 @@ files:
|
|
150
164
|
- spec/unit/virtus/attribute_set/parent_spec.rb
|
151
165
|
- spec/unit/virtus/attribute_set/reset_spec.rb
|
152
166
|
- spec/unit/virtus/class_methods/attribute_spec.rb
|
167
|
+
- spec/unit/virtus/class_methods/attributes_spec.rb
|
153
168
|
- spec/unit/virtus/class_methods/new_spec.rb
|
169
|
+
- spec/unit/virtus/coercion/class_name_reference_spec.rb
|
170
|
+
- spec/unit/virtus/coercion/date/class_methods/to_datetime_spec.rb
|
171
|
+
- spec/unit/virtus/coercion/date/class_methods/to_string_spec.rb
|
172
|
+
- spec/unit/virtus/coercion/date/class_methods/to_time_spec.rb
|
173
|
+
- spec/unit/virtus/coercion/date_time/class_methods/to_date_spec.rb
|
174
|
+
- spec/unit/virtus/coercion/date_time/class_methods/to_string_spec.rb
|
175
|
+
- spec/unit/virtus/coercion/date_time/class_methods/to_time_spec.rb
|
176
|
+
- spec/unit/virtus/coercion/decimal/class_methods/to_float_spec.rb
|
177
|
+
- spec/unit/virtus/coercion/decimal/class_methods/to_integer_spec.rb
|
178
|
+
- spec/unit/virtus/coercion/decimal/class_methods/to_string_spec.rb
|
179
|
+
- spec/unit/virtus/coercion/false_class/class_methods/to_string_spec.rb
|
180
|
+
- spec/unit/virtus/coercion/float/class_methods/to_decimal_spec.rb
|
181
|
+
- spec/unit/virtus/coercion/float/class_methods/to_integer_spec.rb
|
182
|
+
- spec/unit/virtus/coercion/float/class_methods/to_string_spec.rb
|
183
|
+
- spec/unit/virtus/coercion/hash/class_methods/to_array_spec.rb
|
184
|
+
- spec/unit/virtus/coercion/hash/class_methods/to_date_spec.rb
|
185
|
+
- spec/unit/virtus/coercion/hash/class_methods/to_datetime_spec.rb
|
186
|
+
- spec/unit/virtus/coercion/hash/class_methods/to_time_spec.rb
|
187
|
+
- spec/unit/virtus/coercion/integer/class_methods/to_boolean_spec.rb
|
188
|
+
- spec/unit/virtus/coercion/integer/class_methods/to_decimal_spec.rb
|
189
|
+
- spec/unit/virtus/coercion/integer/class_methods/to_float_spec.rb
|
190
|
+
- spec/unit/virtus/coercion/integer/class_methods/to_string_spec.rb
|
191
|
+
- spec/unit/virtus/coercion/object/class_methods/method_missing_spec.rb
|
192
|
+
- spec/unit/virtus/coercion/string/class_methods/to_boolean_spec.rb
|
193
|
+
- spec/unit/virtus/coercion/string/class_methods/to_date_spec.rb
|
194
|
+
- spec/unit/virtus/coercion/string/class_methods/to_datetime_spec.rb
|
195
|
+
- spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb
|
196
|
+
- spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
|
197
|
+
- spec/unit/virtus/coercion/string/class_methods/to_integer_spec.rb
|
198
|
+
- spec/unit/virtus/coercion/string/class_methods/to_time_spec.rb
|
199
|
+
- spec/unit/virtus/coercion/symbol/class_methods/to_string_spec.rb
|
200
|
+
- spec/unit/virtus/coercion/true_class/class_methods/to_string_spec.rb
|
154
201
|
- spec/unit/virtus/descendants_tracker/add_descendant_spec.rb
|
155
202
|
- spec/unit/virtus/descendants_tracker/descendants_spec.rb
|
156
203
|
- spec/unit/virtus/instance_methods/attributes_spec.rb
|
157
204
|
- spec/unit/virtus/instance_methods/element_reference_spec.rb
|
158
205
|
- spec/unit/virtus/instance_methods/element_set_spec.rb
|
206
|
+
- spec/unit/virtus/options/accept_options_spec.rb
|
207
|
+
- spec/unit/virtus/options/accepted_options_spec.rb
|
208
|
+
- spec/unit/virtus/options/options_spec.rb
|
209
|
+
- spec/unit/virtus/type_lookup/determine_type_spec.rb
|
210
|
+
- spec/unit/virtus/type_lookup/primitive_spec.rb
|
159
211
|
- tasks/metrics/ci.rake
|
160
212
|
- tasks/metrics/flay.rake
|
161
213
|
- tasks/metrics/flog.rake
|
@@ -167,7 +219,6 @@ files:
|
|
167
219
|
- tasks/spec.rake
|
168
220
|
- tasks/yard.rake
|
169
221
|
- virtus.gemspec
|
170
|
-
has_rdoc: true
|
171
222
|
homepage: https://github.com/solnic/virtus
|
172
223
|
licenses: []
|
173
224
|
|
@@ -197,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
248
|
requirements: []
|
198
249
|
|
199
250
|
rubyforge_project:
|
200
|
-
rubygems_version: 1.6
|
251
|
+
rubygems_version: 1.8.6
|
201
252
|
signing_key:
|
202
253
|
specification_version: 3
|
203
254
|
summary: Attributes for your plain ruby objects
|
data/History.txt
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
=== v0.0.5 to-be-released
|
2
|
-
|
3
|
-
Details: https://github.com/solnic/virtus/compare/v0.0.4...master
|
4
|
-
|
5
|
-
* [BREAKING CHANGE] Moved Virtus.determine_type to Virtus::Attribute.determine_type (dkubb)
|
6
|
-
* [general] Added backports as a development dependency (dkubb)
|
7
|
-
|
8
|
-
=== v0.0.4 2011-07-08
|
9
|
-
|
10
|
-
* [BREAKING CHANGE] attributes hash has been replaced by a specialized class AttributeSet (dkubb)
|
11
|
-
* [BREAKING CHANGE] Virtus::ClassMethods.attribute returns self instead of a created attribute
|
12
|
-
* [changed] descendants tracking has been extracted into DescendantsTracker module (dkubb)
|
13
|
-
* [changed] Instance #primitive? method has been replaced by class utility method Virtus::Attribute.primitive?
|
14
|
-
* [changed] Virtus::Attribute::String#typecast_to_primitive delegates to Virtus::Typecast::String.call
|
15
|
-
|
16
|
-
Details: https://github.com/solnic/virtus/compare/v0.0.3...v0.0.4
|
17
|
-
|
18
|
-
=== v0.0.3 2011-06-09
|
19
|
-
|
20
|
-
* [BREAKING CHANGE] Attribute classes were moved to Virtus::Attribute namespace
|
21
|
-
* [BREAKING CHANGE] Attribute instance no longer holds the reference to a model
|
22
|
-
* [BREAKING CHANGE] #typecast no longer receives an instance of a model (override #set which calls #typecast if you need that)
|
23
|
-
* [changed] Adding reader/writer methods was moved from the attribute constructor to Virtus::ClassMethods.attribute
|
24
|
-
* [changed] Typecast logic has been moved into separate classes (see Virtus::Typecast)
|
25
|
-
* [added] Virtus::Attribute::DateTime#typecast supports objects which implement #to_datetime
|
26
|
-
* [general] Internals have been cleaned up, simplified and properly documented
|
27
|
-
|
28
|
-
Details: https://github.com/solnic/virtus/compare/v0.0.2...v0.0.3
|
29
|
-
|
30
|
-
=== v0.0.2 2011-06-06
|
31
|
-
|
32
|
-
* [bugfix] Fixed #typecast in custom attribute classes
|
33
|
-
|
34
|
-
Details: https://github.com/solnic/virtus/compare/v0.0.1...v0.0.2
|
35
|
-
|
36
|
-
=== v0.0.1 2011-06-04
|
37
|
-
|
38
|
-
First public release :)
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Virtus
|
2
|
-
module Typecast
|
3
|
-
|
4
|
-
# Typecast defined values into true or false.
|
5
|
-
# See TRUE_VALUES and FALSE_VALUES constants for a reference.
|
6
|
-
class Boolean
|
7
|
-
|
8
|
-
TRUE_VALUES = %w[ 1 t true ].freeze
|
9
|
-
FALSE_VALUES = %w[ 0 f false ].freeze
|
10
|
-
BOOLEAN_MAP = Hash[ TRUE_VALUES.product([ true ]) + FALSE_VALUES.product([ false ]) ].freeze
|
11
|
-
|
12
|
-
# Typecast value to TrueClass or FalseClass
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# Virtus::Typecast::Boolean.call('T') # => true
|
16
|
-
# Virtus::Typecast::Boolean.call('F') # => false
|
17
|
-
#
|
18
|
-
# @param [#to_s]
|
19
|
-
#
|
20
|
-
# @return [Boolean]
|
21
|
-
#
|
22
|
-
# @api public
|
23
|
-
def self.call(value)
|
24
|
-
BOOLEAN_MAP.fetch(value.to_s.downcase, value)
|
25
|
-
end
|
26
|
-
|
27
|
-
end # class Boolean
|
28
|
-
end # module Typecast
|
29
|
-
end # module Virtus
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Virtus
|
2
|
-
module Typecast
|
3
|
-
|
4
|
-
# Typecast numeric values. Supports Integer, Float and BigDecimal
|
5
|
-
class Numeric
|
6
|
-
|
7
|
-
REGEXP = /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/.freeze
|
8
|
-
|
9
|
-
# Typecast value to integer
|
10
|
-
#
|
11
|
-
# @example
|
12
|
-
# Virtus::Typecast::Numeric.to_i('1') # => 1
|
13
|
-
# Virtus::Typecast::Numeric.to_i(1.2) # => 1
|
14
|
-
#
|
15
|
-
# @param [Object] value
|
16
|
-
#
|
17
|
-
# @return [Integer]
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
def self.to_i(value)
|
21
|
-
call(value, :to_i)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Typecast value to float
|
25
|
-
#
|
26
|
-
# @example
|
27
|
-
# Virtus::Typecast::Numeric.to_f('1.2') # => 1.2
|
28
|
-
# Virtus::Typecast::Numeric.to_f(1) # => 1.0
|
29
|
-
#
|
30
|
-
# @param [Object] value
|
31
|
-
#
|
32
|
-
# @return [Float]
|
33
|
-
#
|
34
|
-
# @api public
|
35
|
-
def self.to_f(value)
|
36
|
-
call(value, :to_f)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Typecast value to decimal
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
# Virtus::Typecast::Numeric.to_d('1.2') # => #<BigDecimal:b72157d4,'0.12E1',8(8)>
|
43
|
-
# Virtus::Typecast::Numeric.to_d(1) # => #<BigDecimal:b7212e08,'0.1E1',4(8)>
|
44
|
-
#
|
45
|
-
# @param [Object] value
|
46
|
-
#
|
47
|
-
# @return [BigDecimal]
|
48
|
-
#
|
49
|
-
# @api public
|
50
|
-
def self.to_d(value)
|
51
|
-
if value.kind_of?(::Integer)
|
52
|
-
value.to_s.to_d
|
53
|
-
else
|
54
|
-
call(value, :to_d)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Match numeric string
|
59
|
-
#
|
60
|
-
# @param [#to_str, Numeric] value
|
61
|
-
# value to typecast
|
62
|
-
# @param [Symbol] method
|
63
|
-
# method to typecast with
|
64
|
-
#
|
65
|
-
# @return [Numeric]
|
66
|
-
# number if matched, value if no match
|
67
|
-
#
|
68
|
-
# @api private
|
69
|
-
def self.call(value, method)
|
70
|
-
if value.respond_to?(:to_str)
|
71
|
-
if value.to_str =~ REGEXP
|
72
|
-
$1.send(method)
|
73
|
-
else
|
74
|
-
value
|
75
|
-
end
|
76
|
-
elsif value.respond_to?(method)
|
77
|
-
value.send(method)
|
78
|
-
else
|
79
|
-
value
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
private_class_method :call
|
84
|
-
|
85
|
-
end # class Numeric
|
86
|
-
end # module Typecast
|
87
|
-
end # module Virtus
|