Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: solnic/virtus
base: v0.0.1
...
head fork: solnic/virtus
compare: v0.0.2
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  VERSION
@@ -1 +1 @@
-0.0.1
+0.0.2
View
2  lib/virtus/attributes/attribute.rb
@@ -167,7 +167,7 @@ def get!(model)
# @api private
def set(model, value)
return if value.nil?
- set!(model, primitive?(value) ? value : typecast(value, model))
+ set!(model, typecast(value, model))
end
# Sets instance variable of the attribute
View
36 spec/integration/virtus/attributes/attribute/typecast_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe Virtus::Attributes::Attribute, '#typecast' do
+ let(:attribute_class) do
+ Class.new(Virtus::Attributes::Integer) do
+ def typecast(value, object)
+ super + 1
+ end
+ end
+ end
+
+ let(:model) do
+ model = Class.new do
+ include Virtus
+ end
+ model.attribute(:count, attribute_class)
+ model
+ end
+
+ let(:object) do
+ model.new
+ end
+
+ context 'when overridden' do
+ let(:input_value) { 1 }
+ let(:output_value) { 2 }
+
+ before do
+ object.count = input_value
+ end
+
+ it "peforms custom typecasting" do
+ object.count.should == output_value
+ end
+ end
+end
View
5 virtus.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{virtus}
- s.version = "0.0.1"
+ s.version = "0.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Piotr Solnica}]
- s.date = %q{2011-06-04}
+ s.date = %q{2011-06-06}
s.description = %q{Attributes for your plain ruby objects}
s.email = [%q{piotr@rubyverse.com}]
s.extra_rdoc_files = [
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
"lib/virtus/class_methods.rb",
"lib/virtus/instance_methods.rb",
"lib/virtus/support/chainable.rb",
+ "spec/integration/virtus/attributes/attribute/typecast_spec.rb",
"spec/integration/virtus/class_methods/attribute_spec.rb",
"spec/integration/virtus/class_methods/attributes_spec.rb",
"spec/integration/virtus/class_methods/const_missing_spec.rb",

No commit comments for this range

Something went wrong with that request. Please try again.