diff options
author | Matt Jones <al2o3cr@gmail.com> | 2012-09-13 10:12:11 -0400 |
---|---|---|
committer | Matt Jones <al2o3cr@gmail.com> | 2012-09-13 10:12:11 -0400 |
commit | 46873aeded378bc836fb23925e5ab4f252f57b5b (patch) | |
tree | a0e03a08a4bacde7e3fa1a444b8b0973d82efa5c /activerecord/test/models/admin | |
parent | 01ef633f753cbc97ecd89b464af33e80fd0ca917 (diff) | |
download | rails-46873aeded378bc836fb23925e5ab4f252f57b5b.tar.gz rails-46873aeded378bc836fb23925e5ab4f252f57b5b.tar.bz2 rails-46873aeded378bc836fb23925e5ab4f252f57b5b.zip |
refactor store_accessor
Diffstat (limited to 'activerecord/test/models/admin')
-rw-r--r-- | activerecord/test/models/admin/user.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/models/admin/user.rb b/activerecord/test/models/admin/user.rb index 6c4eb03b06..35170faa76 100644 --- a/activerecord/test/models/admin/user.rb +++ b/activerecord/test/models/admin/user.rb @@ -1,8 +1,16 @@ class Admin::User < ActiveRecord::Base belongs_to :account store :settings, :accessors => [ :color, :homepage ] - store_accessor :settings, :favorite_food + store_accessor :settings, :favorite_food, :phone_number store :preferences, :accessors => [ :remember_login ] store :json_data, :accessors => [ :height, :weight ], :coder => JSON store :json_data_empty, :accessors => [ :is_a_good_guy ], :coder => JSON + + def phone_number + read_store_attribute(:settings, :phone_number).gsub(/(\d{3})(\d{3})(\d{4})/,'(\1) \2-\3') + end + + def phone_number=(value) + write_store_attribute(:settings, :phone_number, value && value.gsub(/[^\d]/,'')) + end end |