virtus 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ script: "bundle exec rake spec"
3
3
  rvm:
4
4
  - 1.8.7
5
5
  - 1.9.2
6
+ - 1.9.3
6
7
  - rbx
7
8
  - rbx-2.0
8
9
  - ree
data/History.md CHANGED
@@ -1,13 +1,20 @@
1
- # v0.0.7 to-be-released
1
+ # v0.0.8 to-be-released
2
+
3
+ * [fixed] Fixed conflict with ActiveModel (RichGuk)
4
+ * [changed] Renamed Coercion::String.to_class => Coercion::String.to_constant (emmanuel)
5
+
6
+ [Compare v0.0.7..master](https://github.com/solnic/virtus/compare/v0.0.7...master)
7
+
8
+ # v0.0.7 2011-07-31
2
9
 
3
10
  * [BREAKING CHANGE] Attribute.primitive? has been removed (solnic)
4
11
  * [fixed] Added missing coercion_method setting to Virtus::Attribute::Object (solnic)
5
12
  * [general] Default value logic has been extracted into Attribute::DefaultValue class (solnic)
6
13
  * [added] Virtus::Attribute::Class (solnic)
7
14
 
8
- [Compare v0.0.5..master](https://github.com/solnic/virtus/compare/v0.0.5...master)
15
+ [Compare v0.0.6..v0.0.7](https://github.com/solnic/virtus/compare/v0.0.6...v0.0.7)
9
16
 
10
- # v0.0.6 2011-07-31
17
+ # v0.0.6 2011-07-30
11
18
 
12
19
  * [BREAKING CHANGE] Moved Virtus.determine_type to a shared module Virtus::TypeLookup (dkubb)
13
20
  * [BREAKING CHANGE] Attribute#typecast_to_primitive has been replaced by Attribute#coerce (solnic)
@@ -16,7 +23,7 @@
16
23
  * [general] Added custom inspect for Attribute classes (solnic)
17
24
  * [general] Added backports as a development dependency (dkubb)
18
25
  * [changed] Options API has been extracted from Attribute to a support module Virtus::Options (solnic)
19
- * [changed] Typecast classes have been replace by a new hierarchy of Coercion classes like Coercion::String, Coercion::Integer etc. (solnic)
26
+ * [changed] Typecast classes have been replaced by a new hierarchy of Coercion classes like Coercion::String, Coercion::Integer etc. (solnic)
20
27
  * [changed] Attribute#get, #get!, #set, #set! & #coerce are now part of the public API (solnic)
21
28
 
22
29
  [Compare v0.0.5..v0.0.6](https://github.com/solnic/virtus/compare/v0.0.5...v0.0.6)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/config/flay.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  ---
2
2
  threshold: 20
3
- total_score: 264
3
+ total_score: 261
@@ -14,7 +14,7 @@ module Virtus
14
14
  #
15
15
  class Class < Object
16
16
  primitive ::Class
17
- coercion_method :to_class
17
+ coercion_method :to_constant
18
18
 
19
19
  end # class Class
20
20
  end # class Attribute
@@ -44,7 +44,7 @@ module Virtus
44
44
  callable? ? call(instance) : value
45
45
  end
46
46
 
47
- private
47
+ private
48
48
 
49
49
  # Evaluates a proc value
50
50
  #
@@ -44,8 +44,8 @@ module Virtus
44
44
  # @api public
45
45
  def attribute(name, type, options = {})
46
46
  attribute = Attribute.determine_type(type).new(name, options)
47
- define_attribute_methods(attribute)
48
- add_attribute(attribute)
47
+ virtus_define_attribute_methods(attribute)
48
+ virtus_add_attribute(attribute)
49
49
  self
50
50
  end
51
51
 
@@ -98,7 +98,7 @@ module Virtus
98
98
  # @return [undefined]
99
99
  #
100
100
  # @api private
101
- def define_attribute_methods(attribute)
101
+ def virtus_define_attribute_methods(attribute)
102
102
  attribute.define_reader_method(self)
103
103
  attribute.define_writer_method(self)
104
104
  include self::AttributeMethods
@@ -111,7 +111,7 @@ module Virtus
111
111
  # @return [undefined]
112
112
  #
113
113
  # @api private
114
- def add_attribute(attribute)
114
+ def virtus_add_attribute(attribute)
115
115
  attributes << attribute
116
116
  descendants.each { |descendant| descendant.attributes.reset }
117
117
  end
@@ -61,6 +61,6 @@ module Virtus
61
61
  to_string(value).to_d
62
62
  end
63
63
 
64
- end
64
+ end # class Numeric
65
65
  end # class Coercion
66
66
  end # module Virtus
@@ -5,6 +5,8 @@ module Virtus
5
5
  class Object < Coercion
6
6
  primitive ::Object
7
7
 
8
+ COERCION_METHOD_REGEXP = /\Ato_/.freeze
9
+
8
10
  # Passthrough given value
9
11
  #
10
12
  # @param [Object] value
@@ -13,7 +15,7 @@ module Virtus
13
15
  #
14
16
  # @api private
15
17
  def self.method_missing(method, *args)
16
- if method.to_s[0, 3] == 'to_' && args.size == 1
18
+ if method.to_s =~ COERCION_METHOD_REGEXP && args.size == 1
17
19
  args.first
18
20
  else
19
21
  super
@@ -14,14 +14,14 @@ module Virtus
14
14
  # Coerce give value to a constant
15
15
  #
16
16
  # @example
17
- # Virtus::Coercion::String.to_class('String') # => String
17
+ # Virtus::Coercion::String.to_constant('String') # => String
18
18
  #
19
19
  # @param [String] value
20
20
  #
21
21
  # @return [Object]
22
22
  #
23
23
  # @api public
24
- def self.to_class(value)
24
+ def self.to_constant(value)
25
25
  # TODO: add support for namespaced classes like 'Virtus::Attribute::String'
26
26
  ::Object.const_get(value)
27
27
  end
@@ -60,7 +60,7 @@ module Virtus
60
60
  coerce_with_method(value, :to_date)
61
61
  end
62
62
 
63
- private
63
+ private
64
64
 
65
65
  # Try to use native coercion method on the given value
66
66
  #
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Virtus::Coercion::String, '.to_class' do
4
- subject { object.to_class(string) }
3
+ describe Virtus::Coercion::String, '.to_constant' do
4
+ subject { object.to_constant(string) }
5
5
 
6
6
  let(:object) { described_class }
7
7
 
data/virtus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{virtus}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Piotr Solnica}]
12
- s.date = %q{2011-07-31}
12
+ s.date = %q{2011-08-25}
13
13
  s.description = %q{Attributes for your plain ruby objects}
14
14
  s.email = [%q{piotr@rubyverse.com}]
15
15
  s.extra_rdoc_files = [
@@ -135,7 +135,7 @@ Gem::Specification.new do |s|
135
135
  "spec/unit/virtus/coercion/integer/class_methods/to_string_spec.rb",
136
136
  "spec/unit/virtus/coercion/object/class_methods/method_missing_spec.rb",
137
137
  "spec/unit/virtus/coercion/string/class_methods/to_boolean_spec.rb",
138
- "spec/unit/virtus/coercion/string/class_methods/to_class_spec.rb",
138
+ "spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb",
139
139
  "spec/unit/virtus/coercion/string/class_methods/to_date_spec.rb",
140
140
  "spec/unit/virtus/coercion/string/class_methods/to_datetime_spec.rb",
141
141
  "spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb",
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: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Piotr Solnica
@@ -15,11 +15,9 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-31 00:00:00 Z
18
+ date: 2011-08-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: backports
22
- prerelease: false
23
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
@@ -31,11 +29,11 @@ dependencies:
31
29
  - 3
32
30
  - 0
33
31
  version: 2.3.0
32
+ name: backports
34
33
  type: :development
34
+ prerelease: false
35
35
  requirement: *id001
36
36
  - !ruby/object:Gem::Dependency
37
- name: jeweler
38
- prerelease: false
39
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
@@ -47,11 +45,11 @@ dependencies:
47
45
  - 6
48
46
  - 4
49
47
  version: 1.6.4
48
+ name: jeweler
50
49
  type: :development
50
+ prerelease: false
51
51
  requirement: *id002
52
52
  - !ruby/object:Gem::Dependency
53
- name: rspec
54
- prerelease: false
55
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
56
54
  none: false
57
55
  requirements:
@@ -63,7 +61,9 @@ dependencies:
63
61
  - 6
64
62
  - 0
65
63
  version: 2.6.0
64
+ name: rspec
66
65
  type: :development
66
+ prerelease: false
67
67
  requirement: *id003
68
68
  description: Attributes for your plain ruby objects
69
69
  email:
@@ -194,7 +194,7 @@ files:
194
194
  - spec/unit/virtus/coercion/integer/class_methods/to_string_spec.rb
195
195
  - spec/unit/virtus/coercion/object/class_methods/method_missing_spec.rb
196
196
  - spec/unit/virtus/coercion/string/class_methods/to_boolean_spec.rb
197
- - spec/unit/virtus/coercion/string/class_methods/to_class_spec.rb
197
+ - spec/unit/virtus/coercion/string/class_methods/to_constant_spec.rb
198
198
  - spec/unit/virtus/coercion/string/class_methods/to_date_spec.rb
199
199
  - spec/unit/virtus/coercion/string/class_methods/to_datetime_spec.rb
200
200
  - spec/unit/virtus/coercion/string/class_methods/to_decimal_spec.rb