Class: Profile

Inherits:
ApplicationRecord 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.

Constant Summary collapse

MAX_TAGS =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Taggable

#build_tags, format_tags, format_tags_for_mail, included, #tag_strings

Methods included from Diaspora::Federated::Base

#object_to_receive

Instance Attribute Details

#tag_stringObject

Returns the value of attribute tag_string


14
15
16
# File 'app/models/profile.rb', line 14

def tag_string
  @tag_string
end

Instance Method Details

#bio_messageObject


113
114
115
# File 'app/models/profile.rb', line 113

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

#construct_full_nameString

Constructs a full name by joining #first_name and #last_name

Returns:


127
128
129
130
# File 'app/models/profile.rb', line 127

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

#date=(params) ⇒ Object


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

def date= params
  if %w(month day).all? {|key| params[key].present? }
    params["year"] = "1004" 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 %w(year month day).all? {|key| params[key].blank? }
    self.birthday = nil
  end
end

#diaspora_handleObject


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

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

#from_omniauth_hash(omniauth_user_hash) ⇒ Object


76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/profile.rb', line 76

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, fallback_to_default: true) ⇒ Object


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/profile.rb', line 56

def image_url(size: :thumb_large, fallback_to_default: true)
  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

  if result
    if AppConfig.privacy.camo.proxy_remote_pod_images?
      Diaspora::Camo.image_url(result)
    else
      result
    end
  elsif fallback_to_default
    ActionController::Base.helpers.image_path("user/default.png")
  end
end

#image_url=(url) ⇒ Object


88
89
90
# File 'app/models/profile.rb', line 88

def image_url=(url)
  super(build_image_url(url))
end

#image_url_medium=(url) ⇒ Object


96
97
98
# File 'app/models/profile.rb', line 96

def image_url_medium=(url)
  super(build_image_url(url))
end

#image_url_small=(url) ⇒ Object


92
93
94
# File 'app/models/profile.rb', line 92

def image_url_small=(url)
  super(build_image_url(url))
end

#location_messageObject


117
118
119
# File 'app/models/profile.rb', line 117

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

#public?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'app/models/profile.rb', line 47

def public?
  public_details?
end

#subscribersObject


43
44
45
# File 'app/models/profile.rb', line 43

def subscribers
  Person.joins(:contacts).where(contacts: {user_id: person.owner_id})
end

#tombstone!Object


132
133
134
135
136
137
138
139
140
# File 'app/models/profile.rb', line 132

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