Permalink
Browse files

some refactoring regarding the law of demeter

  • Loading branch information...
1 parent f0619db commit e70e48d6caf5c3a314ba8896b37c6b98b7edc816 @jhass jhass committed Sep 9, 2012
Showing with 150 additions and 115 deletions.
  1. +1 −1 app/controllers/application_controller.rb
  2. +5 −5 app/controllers/conversations_controller.rb
  3. +1 −1 app/controllers/messages_controller.rb
  4. +1 −1 app/controllers/photos_controller.rb
  5. +1 −1 app/controllers/profiles_controller.rb
  6. +1 −1 app/controllers/reshares_controller.rb
  7. +4 −4 app/controllers/services_controller.rb
  8. +2 −2 app/controllers/users_controller.rb
  9. +3 −3 app/helpers/contacts_helper.rb
  10. +1 −1 app/helpers/invitation_codes_helper.rb
  11. +3 −3 app/helpers/mobile_helper.rb
  12. +1 −1 app/helpers/notifications_helper.rb
  13. +3 −3 app/helpers/posts_helper.rb
  14. +3 −2 app/mailers/notification_mailers/also_commented.rb
  15. +4 −0 app/mailers/notification_mailers/base.rb
  16. +2 −2 app/mailers/notification_mailers/comment_on_post.rb
  17. +1 −1 app/mailers/notification_mailers/confirm_email.rb
  18. +2 −1 app/mailers/notification_mailers/liked.rb
  19. +2 −1 app/mailers/notification_mailers/mentioned.rb
  20. +1 −1 app/mailers/notification_mailers/private_message.rb
  21. +3 −1 app/mailers/notification_mailers/reshared.rb
  22. +1 −1 app/mailers/notifier.rb
  23. +3 −1 app/models/block.rb
  24. +4 −0 app/models/comment.rb
  25. +4 −1 app/models/contact.rb
  26. +2 −0 app/models/invitation_code.rb
  27. +2 −0 app/models/message.rb
  28. +3 −1 app/models/person.rb
  29. +1 −0 app/models/photo.rb
  30. +2 −1 app/models/reshare.rb
  31. +4 −0 app/models/status_message.rb
  32. +5 −2 app/models/user.rb
  33. +3 −3 app/presenters/o_embed_presenter.rb
  34. +4 −4 app/presenters/person_presenter.rb
  35. +1 −1 app/presenters/post_presenter.rb
  36. +1 −1 app/views/community_spotlight/_user.html.haml
  37. +2 −2 app/views/contacts/index.html.haml
  38. +2 −2 app/views/contacts/sharing.haml
  39. +1 −1 app/views/notifications/_notify_popup_item.haml
  40. +2 −2 app/views/notifier/also_commented.markerb
  41. +1 −1 app/views/notifier/comment_on_post.markerb
  42. +3 −3 app/views/notifier/confirm_email.markerb
  43. +3 −3 app/views/notifier/liked.markerb
  44. +1 −1 app/views/notifier/mentioned.markerb
  45. +2 −2 app/views/notifier/reshared.markerb
  46. +2 −2 app/views/notifier/started_sharing.markerb
  47. +8 −8 app/views/people/_profile_sidebar.html.haml
  48. +1 −1 app/views/people/_sub_header.html.haml
  49. +1 −1 app/views/photos/_photo.haml
  50. +1 −1 app/views/posts/_photo.html.haml
  51. +5 −5 app/views/publics/hcard.haml
  52. +1 −1 app/views/shared/_photo_area.mobile.haml
  53. +1 −1 app/views/status_messages/_status_message.mobile.haml
  54. +1 −1 app/views/users/getting_started.haml
  55. +1 −1 app/views/users/privacy_settings.html.haml
  56. +5 −5 app/views/users/public.atom.builder
  57. +1 −1 lib/collect_user_photos.rb
  58. +2 −2 lib/diaspora/exporter.rb
  59. +3 −2 lib/diaspora/relayable.rb
  60. +2 −1 lib/diaspora/shareable.rb
  61. +1 −1 lib/email_inviter.rb
  62. +3 −3 lib/postzord/dispatcher.rb
  63. +2 −2 lib/postzord/receiver/local_batch.rb
  64. +1 −1 lib/postzord/receiver/private.rb
  65. +3 −3 lib/postzord/receiver/public.rb
  66. +2 −2 lib/stream/base.rb
  67. +1 −1 spec/presenters/post_presenter_spec.rb
@@ -86,7 +86,7 @@ def redirect_unless_admin
def set_grammatical_gender
if (user_signed_in? && I18n.inflector.inflected_locale?)
- gender = current_user.profile.gender.to_s.tr('!()[]"\'`*=|/\#.,-:', '').downcase
+ gender = current_user.gender.to_s.tr('!()[]"\'`*=|/\#.,-:', '').downcase
unless gender.empty?
i_langs = I18n.inflector.inflected_locales(:gender)
i_langs.delete I18n.locale
@@ -5,10 +5,10 @@ class ConversationsController < ApplicationController
def index
@conversations = Conversation.joins(:conversation_visibilities).where(
- :conversation_visibilities => {:person_id => current_user.person.id}).paginate(
+ :conversation_visibilities => {:person_id => current_user.person_id}).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
- @visibilities = ConversationVisibility.where(:person_id => current_user.person.id).paginate(
+ @visibilities = ConversationVisibility.where(:person_id => current_user.person_id).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@unread_counts = {}
@@ -18,7 +18,7 @@ def index
@conversations.each { |c| @authors[c.id] = c.last_author }
@conversation = Conversation.joins(:conversation_visibilities).where(
- :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
+ :conversation_visibilities => {:person_id => current_user.person_id, :conversation_id => params[:conversation_id]}).first
respond_with do |format|
format.html
@@ -31,7 +31,7 @@ def create
contact.person_id
end
- params[:conversation][:participant_ids] = person_ids | [current_user.person.id]
+ params[:conversation][:participant_ids] = person_ids | [current_user.person_id]
params[:conversation][:author] = current_user.person
message_text = params[:conversation].delete(:text)
params[:conversation][:messages_attributes] = [ {:author => current_user.person, :text => message_text }]
@@ -52,7 +52,7 @@ def create
def show
if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
- :conversation_visibilities => {:person_id => current_user.person.id}).first
+ :conversation_visibilities => {:person_id => current_user.person_id}).first
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0
@visibility.save
@@ -11,7 +11,7 @@ class MessagesController < ApplicationController
def create
cnv = Conversation.joins(:conversation_visibilities).where(:id => params[:conversation_id],
- :conversation_visibilities => {:person_id => current_user.person.id}).first
+ :conversation_visibilities => {:person_id => current_user.person_id}).first
if cnv
message = Message.new(:conversation_id => cnv.id, :text => params[:message][:text], :author => current_user.person)
@@ -58,7 +58,7 @@ def create
end
def make_profile_photo
- author_id = current_user.person.id
+ author_id = current_user.person_id
@photo = Photo.where(:id => params[:photo_id], :author_id => author_id).first
if @photo
@@ -42,7 +42,7 @@ def update
@profile_attrs[:nsfw] ||= false
if params[:photo_id]
- @profile_attrs[:photo] = Photo.where(:author_id => current_user.person.id, :id => params[:photo_id]).first
+ @profile_attrs[:photo] = Photo.where(:author_id => current_user.person_id, :id => params[:photo_id]).first
end
if current_user.update_profile(@profile_attrs)
@@ -6,7 +6,7 @@ def create
@reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid])
if @reshare.save
current_user.add_to_streams(@reshare, current_user.aspects)
- current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root.author)
+ current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root_author)
end
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
@@ -33,9 +33,9 @@ def create
current_user.services << service
if service.persisted?
- fetch_photo = current_user.person.profile[:image_url].blank?
+ fetch_photo = current_user.profile[:image_url].blank?
- current_user.update_profile(current_user.person.profile.from_omniauth_hash(user))
+ current_user.update_profile(current_user.profile.from_omniauth_hash(user))
Resque.enqueue(Jobs::FetchProfilePhoto, current_user.id, service.id, user["image"]) if fetch_photo
flash[:notice] = I18n.t 'services.create.success'
@@ -44,7 +44,7 @@ def create
if existing_service = Service.where(:type => service.type.to_s, :uid => service.uid).first
flash[:error] << I18n.t('services.create.already_authorized',
- :diaspora_id => existing_service.user.person.profile.diaspora_handle,
+ :diaspora_id => existing_service.user.profile.diaspora_handle,
:service_name => provider.camelize )
end
end
@@ -65,4 +65,4 @@ def destroy
redirect_to services_url
end
-end
+end
@@ -101,7 +101,7 @@ def public
if @user = User.find_by_username(params[:username])
respond_to do |format|
format.atom do
- @posts = StatusMessage.where(:author_id => @user.person.id, :public => true).order('created_at DESC').limit(25)
+ @posts = StatusMessage.where(:author_id => @user.person_id, :public => true).order('created_at DESC').limit(25)
end
format.any { redirect_to person_path(@user.person) }
@@ -140,7 +140,7 @@ def user_photo
username = params[:username].split('@')[0]
user = User.find_by_username(username)
if user.present?
- redirect_to user.profile.image_url
+ redirect_to user.image_url
else
render :nothing => true, :status => 404
end
@@ -6,9 +6,9 @@ def contact_aspect_dropdown(contact)
:action => 'destroy',
:id => 42,
:aspect_id => @aspect.id,
- :person_id => contact.person.id
+ :person_id => contact.person_id
},
- :title => t('.remove_person_from_aspect', :person_name => contact.person.first_name, :aspect_name => @aspect.name),
+ :title => t('.remove_person_from_aspect', :person_name => contact.person_first_name, :aspect_name => @aspect.name),
:method => 'delete')
else
@@ -17,4 +17,4 @@ def contact_aspect_dropdown(contact)
:current_user => current_user }
end
end
-end
+end
@@ -4,7 +4,7 @@ def invite_welcome_message
content_tag(:div, :class => 'media well') do
person_image_link(invite.user.person, :class => 'img') +
content_tag(:div, :class => 'bd') do
- I18n.translate('invitation_codes.excited', :name => invite.user.name)
+ I18n.translate('invitation_codes.excited', :name => invite.user_name)
end
end
end
@@ -8,11 +8,11 @@ def mobile_reshare_icon(post)
if (post.public? || reshare?(post)) && (user_signed_in? && post.author != current_user.person)
root = reshare?(post) ? post.root : post
- if root.author != current_user.person.id
- reshare = Reshare.where(:author_id => current_user.person.id,
+ if root.author != current_user.person_id
+ reshare = Reshare.where(:author_id => current_user.person_id,
:root_guid => root.guid).first
klass = reshare.present? ? "active" : "inactive"
- link_to '', reshares_path(:root_guid => root.guid), :title => t('reshares.reshare.reshare_confirmation', :author => root.author.name), :class => "image_link reshare_action #{klass}"
+ link_to '', reshares_path(:root_guid => root.guid), :title => t('reshares.reshare.reshare_confirmation', :author => root.author_name), :class => "image_link reshare_action #{klass}"
end
end
end
@@ -13,7 +13,7 @@ def object_link(note, actors)
end
elsif note.instance_of?(Notifications::CommentOnPost) || note.instance_of?(Notifications::AlsoCommented) || note.instance_of?(Notifications::Reshared) || note.instance_of?(Notifications::Liked)
if post = note.linked_object
- translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author.name), :post_link => link_to(t('notifications.post'), post_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
+ translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author_name), :post_link => link_to(t('notifications.post'), post_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
else
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end
@@ -5,14 +5,14 @@
module PostsHelper
def post_page_title(post, opts={})
if post.is_a?(Photo)
- I18n.t "posts.show.photos_by", :count => 1, :author => post.status_message.author.name
+ I18n.t "posts.show.photos_by", :count => 1, :author => post.status_message_author_name
elsif post.is_a?(Reshare)
- I18n.t "posts.show.reshare_by", :author => post.author.name
+ I18n.t "posts.show.reshare_by", :author => post.author_name
else
if post.text.present?
truncate(post.text(:plain_text => true), :length => opts.fetch(:length, 20))
elsif post.respond_to?(:photos) && post.photos.present?
- I18n.t "posts.show.photos_by", :count => post.photos.size, :author => post.author.name
+ I18n.t "posts.show.photos_by", :count => post.photos.size, :author => post.author_name
end
end
end
@@ -3,13 +3,14 @@ class AlsoCommented < NotificationMailers::Base
include ActionView::Helpers::TextHelper
attr_accessor :comment
+ delegate :post, to: :comment, prefix: true
def set_headers(comment_id)
@comment = Comment.find_by_id(comment_id)
if mail?
- @headers[:from] = "\"#{@comment.author.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
- @headers[:subject] = truncate(@comment.parent.comment_email_subject, :length => TRUNCATION_LEN)
+ @headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
+ @headers[:subject] = truncate(@comment.comment_email_subject, :length => TRUNCATION_LEN)
@headers[:subject] = "Re: #{@headers[:subject]}"
end
end
@@ -3,6 +3,10 @@ module NotificationMailers
class Base
attr_accessor :recipient, :sender
+
+ delegate :unconfirmed_email, :confirm_email_token,
+ :first_name, to: :recipient, prefix: true
+ delegate :first_name, :name, :sender, to: :sender, prefix: true
def initialize(recipient_id, sender_id=nil, *args)
@headers = {}
@@ -7,8 +7,8 @@ class CommentOnPost < NotificationMailers::Base
def set_headers(comment_id)
@comment = Comment.find(comment_id)
- @headers[:from] = "\"#{@comment.author.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
- @headers[:subject] = truncate(@comment.parent.comment_email_subject, :length => TRUNCATION_LEN)
+ @headers[:from] = "\"#{@comment.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
+ @headers[:subject] = truncate(@comment.comment_email_subject, :length => TRUNCATION_LEN)
@headers[:subject] = "Re: #{@headers[:subject]}"
end
end
@@ -1,7 +1,7 @@
module NotificationMailers
class ConfirmEmail < NotificationMailers::Base
def set_headers
- @headers[:to] = name_and_address(@recipient.profile.first_name, @recipient.unconfirmed_email)
+ @headers[:to] = name_and_address(@recipient.first_name, @recipient.unconfirmed_email)
@headers[:subject] = I18n.t('notifier.confirm_email.subject', :unconfirmed_email => @recipient.unconfirmed_email)
end
end
@@ -1,11 +1,12 @@
module NotificationMailers
class Liked < NotificationMailers::Base
attr_accessor :like
+ delegate :target, to: :like, prefix: true
def set_headers(like_id)
@like = Like.find(like_id)
@headers[:subject] = I18n.t('notifier.liked.liked', :name => @sender.name)
end
end
-end
+end
@@ -1,11 +1,12 @@
module NotificationMailers
class Mentioned < NotificationMailers::Base
attr_accessor :post
+ delegate :author_name, to: :post, prefix: true
def set_headers(target_id)
@post = Mention.find_by_id(target_id).post
@headers[:subject] = I18n.t('notifier.mentioned.subject', :name => @sender.name)
end
end
-end
+end
@@ -7,7 +7,7 @@ def set_headers(message_id)
@conversation = @message.conversation
@participants = @conversation.participants
- @headers[:from] = "\"#{@message.author.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
+ @headers[:from] = "\"#{@message.author_name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>"
@headers[:subject] = @conversation.subject.strip
@headers[:subject] = "Re: #{@headers[:subject]}" if @conversation.messages.size > 1
end
@@ -1,11 +1,13 @@
module NotificationMailers
class Reshared < NotificationMailers::Base
attr_accessor :reshare
+
+ delegate :root, to: :reshare, prefix: true
def set_headers(reshare_id)
@reshare = Reshare.find(reshare_id)
@headers[:subject] = I18n.t('notifier.reshared.reshared', :name => @sender.name)
end
end
-end
+end
View
@@ -43,7 +43,7 @@ def invite(email, message, inviter, invitation_code, locale)
@invitation_code = invitation_code
mail_opts = {:to => email, :from => AppConfig[:smtp_sender_address],
- :subject => I18n.t('notifier.invited_you', :name => @inviter.person.name),
+ :subject => I18n.t('notifier.invited_you', :name => @inviter.name),
:host => AppConfig[:pod_uri].host}
I18n.with_locale(locale) do
View
@@ -2,6 +2,8 @@ class Block < ActiveRecord::Base
belongs_to :person
belongs_to :user
+ delegate :name, to: :person, prefix: true
+
validates :user_id, :presence => true
validates :person_id, :presence => true, :uniqueness => { :scope => :user_id }
@@ -12,4 +14,4 @@ def not_blocking_yourself
errors[:person_id] << "stop blocking yourself!"
end
end
-end
+end
View
@@ -22,6 +22,10 @@ class Comment < ActiveRecord::Base
belongs_to :commentable, :touch => true, :polymorphic => true
alias_attribute :post, :commentable
belongs_to :author, :class_name => 'Person'
+
+ delegate :name, to: :author, prefix: true
+ delegate :comment_email_subject, to: :parent
+ delegate :author_name, to: :parent, prefix: true
validates :text, :presence => true, :length => {:maximum => 65535}
validates :parent, :presence => true #should be in relayable (pending on fixing Message)
View
@@ -7,6 +7,9 @@ class Contact < ActiveRecord::Base
belongs_to :person
validates :person, :presence => true
+
+ delegate :name, :diaspora_handle, :guid, :first_name,
+ to: :person, prefix: true
has_many :aspect_memberships
has_many :aspects, :through => :aspect_memberships
@@ -72,7 +75,7 @@ def contacts
incoming_aspects = Aspect.where(
:user_id => self.person.owner_id,
:contacts_visible => true).joins(:contacts).where(
- :contacts => {:person_id => self.user.person.id}).select('aspects.id')
+ :contacts => {:person_id => self.user.person_id}).select('aspects.id')
incoming_aspect_ids = incoming_aspects.map{|a| a.id}
similar_contacts = Person.joins(:contacts => :aspect_memberships).where(
:aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT people.*')
@@ -5,6 +5,8 @@ class InvitationCode < ActiveRecord::Base
before_create :generate_token, :set_default_invite_count
+ delegate :name, to: :user, prefix: true
+
def to_param
token
end
View
@@ -11,6 +11,8 @@ class Message < ActiveRecord::Base
belongs_to :author, :class_name => 'Person'
belongs_to :conversation, :touch => true
+
+ delegate :name, to: :author, prefix: true
validates :text, :presence => true
validate :participant_of_parent_conversation
View
@@ -32,7 +32,9 @@ class Person < ActiveRecord::Base
xml_attr :exported_key
has_one :profile, :dependent => :destroy
- delegate :last_name, :image_url, :to => :profile
+ delegate :last_name, :image_url, :tag_string, :bio, :location,
+ :gender, :birthday, :formatted_birthday, :tags, :searchable,
+ to: :profile
accepts_nested_attributes_for :profile
before_validation :downcase_diaspora_handle
View
@@ -41,6 +41,7 @@ class Photo < ActiveRecord::Base
belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid
validates_associated :status_message
+ delegate :author_name, to: :status_message, prefix: true
attr_accessible :text, :pending
validate :ownership_of_status_message
Oops, something went wrong.

0 comments on commit e70e48d

Please sign in to comment.