0.0
No commit activity in last 3 years
No release in over 3 years
A type cast for ActiveModel
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0

Runtime

>= 4.2.0
 Project Readme

TypeAttributes

Deprecation warning

This gem no longer maintained.

In Rails5.2, Rails support .attribute method with ActiveModel::Attributes. Please remove this gem and replace type_attribute(:name, :type) with attribute(:name, :type).

In under Rails 5.2, please use ActiveModelAttributes backport instead of.


TypeAttributes defines .type_attribute method to cast value with ActiveModel::Type. Supported versions are Rails 4.2, 5.0 and 5.1.

class User
  include TypeAttributes

  type_attribute :id, :integer
end

user = User.new
user.id = '1'
user.id == 1 #=> true
# Lookup type from `ActiveModel::Type.lookup(type)` 
# ActiveModel::Type.registry.send(:registrations).map { |type| type.send(:name) }
:big_integer
:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:string
:text
:time

Deprecation Warning

Typed attribute is already supported in Rails5.2 rails/rails#30985

You shouldn't use this gem, and replace it as following.

# before
type_attribute :key, :integer

# after
attribute :key, :integer

Installation

Add this line to your application's Gemfile:

gem 'type_attributes'

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/alpaca-tc/type_attributes.