aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/models/contact.rb
blob: bcfd267a3447935a0fa78205ea5adc7447935626 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Contact
  extend ActiveModel::Naming
  include ActiveModel::Conversion
  include ActiveModel::Validations

  include ActiveModel::Serializers::JSON
  include ActiveModel::Serializers::Xml

  attr_accessor :id, :name, :age, :created_at, :awesome, :preferences
  attr_accessor :address, :friends, :contact

  def social
    %w(twitter github)
  end

  def network
    { git: :github }
  end

  def initialize(options = {})
    options.each { |name, value| send("#{name}=", value) }
  end

  def pseudonyms
    nil
  end

  def persisted?
    id
  end

  def attributes=(hash)
    hash.each do |k, v|
      instance_variable_set("@#{k}", v)
    end
  end

  def attributes
    instance_values.except("address", "friends", "contact")
  end
end