No description, website, or topics provided.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
CHANGELOG
Gemfile
LICENSE
Manifest
README.rdoc
Rakefile
init.rb
install.rb
typed_serialize.gemspec
uninstall.rb

README.rdoc

Typed Serialize

Typed serialize makes sure your serialized attribute is always the specified type. This is especially nice for serialized hashes and new models.

Example

class User < ActiveRecord::Base
  typed_serialize :settings, Hash
end

User.new.settings        # => {}

u = User.new
u.settings[:theme] = 1
u.settings               # => { :theme => 1 }

Define serialized attributes

Avalaible only for Hash columns!!!

class User < ActiveRecord::Base
  typed_serialize :settings, Hash

  #parametr :in is required and describe hash owner 
  serialized_accessor :photo, :city, :nickname, :in=>:settings

end

u = User.new
u.photo = '/home/photos/me.png'
u.photo
=> '/home/photos/me.png'
u.settings
=>{:photo=>'/home/photos/me.png'}

or even better

class User < ActiveRecord::Base
  # paramter :in set automatic
  typed_serialize :settings, Hash, :photo, :city, :nickname

end

u = User.new(:city=>'NY')
u.city
=> 'NY'

If you want add prefix to you virtual attributes it's easy enough - just add :prefix=>true to options

class User < ActiveRecord::Base
  typed_serialize :settings, Hash, :photo, :prefix=>true

  #or

  serialized_accessor :logo, :in=>:settings, :prefix=>true

end

user = User.new
user.settings_logo = "crazy_avatar.jpg"
user.settings
=> {:logo=>"crazy_avatar.jpg"}

Also avalaible serialized_reader and serialized_writer.

Install

As a Rails plugin:

./script/plugin install git://github.com/jqr/typed_serialize.git

Prefer gems? Add this to your environment.rb and run the following command.

config.gem 'typed_serialize'

$ rake gems:install

Docs

rdoc.info/projects/jqr/typed_serialize

Contributors

  • Toby Matejovsky (toby.matejovsky@gmail.com)

  • Sergey Pchelincev (jalkoby91@gmail.com)

Homepage

github.com/jqr/typed_serialize

License

Copyright © 2008 Elijah Miller <elijah.miller@gmail.com>, released under the MIT license