Sha256: 0f58de1e14065e115b4a1978ff02b9769ac4ebef65f7919433a931cef0ebb7ed

Contents?: true

Size: 1.03 KB

Versions: 18

Compression:

Stored size: 1.03 KB

Contents

class Admin::User < ActiveRecord::Base
  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

  belongs_to :account
  store :params, accessors: [ :token ], coder: YAML
  store :settings, :accessors => [ :color, :homepage ]
  store_accessor :settings, :favorite_food
  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

  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

  def color
    super || 'red'
  end

  def color=(value)
    value = 'blue' unless %w(black red green blue).include?(value)
    super
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
ibm_db-5.2.0 test/models/admin/user.rb
ibm_db-5.1.0 test/models/admin/user.rb
ibm_db-5.0.5 test/models/admin/user.rb
ibm_db-5.0.4 test/models/admin/user.rb
ibm_db-5.0.3 test/models/admin/user.rb
ibm_db-5.0.2 test/models/admin/user.rb
ibm_db-4.0.0-x86-mingw32 test/models/admin/user.rb
ibm_db-4.0.0 test/models/admin/user.rb
ibm_db-3.0.4-x86-mingw32 test/models/admin/user.rb
ibm_db-3.0.4 test/models/admin/user.rb
ibm_db-3.0.3-x86-mingw32 test/models/admin/user.rb
ibm_db-3.0.3 test/models/admin/user.rb
ibm_db-3.0.2-x86-mingw32 test/models/admin/user.rb
ibm_db-3.0.2 test/models/admin/user.rb
activejob-lock-0.0.2 rails/activerecord/test/models/admin/user.rb
ibm_db-3.0.1 test/models/admin/user.rb
ibm_db-3.0.1-x86-mingw32 test/models/admin/user.rb
activejob-lock-0.0.1 rails/activerecord/test/models/admin/user.rb