Class: Profile

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Diaspora::Federated::Base, Diaspora::Taggable
Defined in:
app/models/profile.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Taggable

#build_tags, format_tags, included, #tag_strings

Methods included from Diaspora::Federated::Base

included

Instance Attribute Details

#tag_stringObject

Returns the value of attribute tag_string


11
12
13
# File 'app/models/profile.rb', line 11

def tag_string
  @tag_string
end

Instance Method Details

#bio_messageObject


135
136
137
# File 'app/models/profile.rb', line 135

def bio_message
  @bio_message ||= Diaspora::MessageRenderer.new(bio)
end

#construct_full_nameString

Constructs a full name by joining #first_name and #last_name


154
155
156
157
# File 'app/models/profile.rb', line 154

def construct_full_name
  self.full_name = [self.first_name, self.last_name].join(' ').downcase.strip
  self.full_name
end

#date=(params) ⇒ Object


118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/profile.rb', line 118

def date= params
  if ['month', 'day'].all? { |key| params[key].present?  }
    params['year'] = '1000' if params['year'].blank?
    if Date.valid_civil?(params['year'].to_i, params['month'].to_i, params['day'].to_i)
      self.birthday = Date.new(params['year'].to_i, params['month'].to_i, params['day'].to_i)
    else
      @invalid_birthday_date = true
    end
  elsif [ 'year', 'month', 'day'].all? { |key| params[key].blank? }
    self.birthday = nil
  end
end

#diaspora_handleObject


63
64
65
66
# File 'app/models/profile.rb', line 63

def diaspora_handle
  #get the parent diaspora handle, unless we want to access a profile without a person
  (self.person) ? self.person.diaspora_handle : self[:diaspora_handle]
end

#formatted_birthdayObject


131
132
133
# File 'app/models/profile.rb', line 131

def formatted_birthday
  birthday.to_s(:long).gsub(', 1000', '') if birthday.present?
end

#from_omniauth_hash(omniauth_user_hash) ⇒ Object


79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/profile.rb', line 79

def from_omniauth_hash(omniauth_user_hash)
  mappings = {"description" => "bio",
             'image' => 'image_url',
             'name' => 'first_name',
             'location' =>  'location',
              }

  update_hash = Hash[ omniauth_user_hash.map {|k, v| [mappings[k], v] } ]

  self.attributes.merge(update_hash){|key, old, new| old.blank? ? new : old}
end

#image_url(size = :thumb_large) ⇒ Object


68
69
70
71
72
73
74
75
76
77
# File 'app/models/profile.rb', line 68

def image_url(size = :thumb_large)
  result = if size == :thumb_medium && self[:image_url_medium]
             self[:image_url_medium]
           elsif size == :thumb_small && self[:image_url_small]
             self[:image_url_small]
           else
             self[:image_url]
           end
  result || '/assets/user/default.png'
end

#image_url=(url) ⇒ Object


91
92
93
94
95
96
97
98
# File 'app/models/profile.rb', line 91

def image_url= url
  return image_url if url == ''
  if url.nil? || url.match(/^https?:\/\//)
    super(url)
  else
    super(absolutify_local_url(url))
  end
end

#image_url_medium=(url) ⇒ Object


109
110
111
112
113
114
115
116
# File 'app/models/profile.rb', line 109

def image_url_medium= url
  return image_url if url == ''
  if url.nil? || url.match(/^https?:\/\//)
    super(url)
  else
    super(absolutify_local_url(url))
  end
end

#image_url_small=(url) ⇒ Object


100
101
102
103
104
105
106
107
# File 'app/models/profile.rb', line 100

def image_url_small= url
  return image_url if url == ''
  if url.nil? || url.match(/^https?:\/\//)
    super(url)
  else
    super(absolutify_local_url(url))
  end
end

#location_messageObject


139
140
141
# File 'app/models/profile.rb', line 139

def location_message
  @location_message ||= Diaspora::MessageRenderer.new(location)
end

#receive(user, person) ⇒ Object


55
56
57
58
59
60
61
# File 'app/models/profile.rb', line 55

def receive(user, person)
  Rails.logger.info("event=receive payload_type=profile sender=#{person} to=#{user}")
  profiles_attr = self.attributes.merge('tag_string' => self.tag_string).slice('diaspora_handle', 'first_name', 'last_name', 'image_url', 'image_url_small', 'image_url_medium', 'birthday', 'gender', 'bio', 'location', 'searchable', 'nsfw', 'tag_string')
  person.profile.update_attributes(profiles_attr)

  person.profile
end

#subscribers(user) ⇒ Object


51
52
53
# File 'app/models/profile.rb', line 51

def subscribers(user)
  Person.joins(:contacts).where(:contacts => {:user_id => user.id})
end

#tombstone!Object


159
160
161
162
163
164
165
166
# File 'app/models/profile.rb', line 159

def tombstone!
  self.taggings.delete_all
  clearable_fields.each do |field|
    self[field] = nil
  end
  self[:searchable] = false
  self.save
end