2010-04-14 13:15:27 -04:00
|
|
|
class Admin::User < ActiveRecord::Base
|
2013-01-23 09:54:56 -05:00
|
|
|
class Coder
|
|
|
|
def initialize(default = {})
|
|
|
|
@default = default
|
|
|
|
end
|
|
|
|
|
|
|
|
def dump(o)
|
|
|
|
ActiveSupport::JSON.encode(o || @default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def load(s)
|
|
|
|
s.present? ? ActiveSupport::JSON.decode(s) : @default.clone
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-14 13:15:27 -04:00
|
|
|
belongs_to :account
|
2014-01-06 10:40:32 -05:00
|
|
|
store :params, accessors: [ :token ], coder: YAML
|
2016-08-06 13:37:57 -04:00
|
|
|
store :settings, accessors: [ :color, :homepage ]
|
2012-09-15 02:29:22 -04:00
|
|
|
store_accessor :settings, :favorite_food
|
2016-08-06 13:37:57 -04:00
|
|
|
store :preferences, accessors: [ :remember_login ]
|
|
|
|
store :json_data, accessors: [ :height, :weight ], coder: Coder.new
|
|
|
|
store :json_data_empty, accessors: [ :is_a_good_guy ], coder: Coder.new
|
2012-09-13 10:12:11 -04:00
|
|
|
|
|
|
|
def phone_number
|
2016-10-28 23:05:58 -04:00
|
|
|
read_store_attribute(:settings, :phone_number).gsub(/(\d{3})(\d{3})(\d{4})/, '(\1) \2-\3')
|
2012-09-13 10:12:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def phone_number=(value)
|
2016-10-28 23:05:58 -04:00
|
|
|
write_store_attribute(:settings, :phone_number, value && value.gsub(/[^\d]/, ""))
|
2012-09-13 10:12:11 -04:00
|
|
|
end
|
2013-02-11 09:00:55 -05:00
|
|
|
|
|
|
|
def color
|
2016-08-06 12:26:20 -04:00
|
|
|
super || "red"
|
2013-02-11 09:00:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def color=(value)
|
2016-08-06 12:26:20 -04:00
|
|
|
value = "blue" unless %w(black red green blue).include?(value)
|
2013-02-11 09:00:55 -05:00
|
|
|
super
|
|
|
|
end
|
2011-10-13 18:54:53 -04:00
|
|
|
end
|