about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authoralpaca-tc <alpaca-tc@alpaca.tc>2017-05-19 18:41:45 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-05-19 11:41:45 +0200
commit198ae3e36688e6282c6d1a699b4e1874d642f1e9 (patch)
tree64b1770e564d62407ed18fa8b94c27522265d296 /app
parent6e4c7d62118d5d1f2e966950edfdbc80cebd4d7c (diff)
Define instance method outside #included (#3128)
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/account_avatar.rb12
-rw-r--r--app/models/concerns/account_header.rb12
-rw-r--r--app/models/concerns/account_interactions.rb118
-rw-r--r--app/models/concerns/streamable.rb48
-rw-r--r--app/models/concerns/targetable.rb8
5 files changed, 98 insertions, 100 deletions
diff --git a/app/models/concerns/account_avatar.rb b/app/models/concerns/account_avatar.rb
index 73507a328..a6527a85b 100644
--- a/app/models/concerns/account_avatar.rb
+++ b/app/models/concerns/account_avatar.rb
@@ -20,13 +20,13 @@ module AccountAvatar
     has_attached_file :avatar, styles: ->(f) { avatar_styles(f) }, convert_options: { all: '-quality 80 -strip' }
     validates_attachment_content_type :avatar, content_type: IMAGE_MIME_TYPES
     validates_attachment_size :avatar, less_than: 2.megabytes
+  end
 
-    def avatar_original_url
-      avatar.url(:original)
-    end
+  def avatar_original_url
+    avatar.url(:original)
+  end
 
-    def avatar_static_url
-      avatar_content_type == 'image/gif' ? avatar.url(:static) : avatar_original_url
-    end
+  def avatar_static_url
+    avatar_content_type == 'image/gif' ? avatar.url(:static) : avatar_original_url
   end
 end
diff --git a/app/models/concerns/account_header.rb b/app/models/concerns/account_header.rb
index 4d96e990a..4ba9212a2 100644
--- a/app/models/concerns/account_header.rb
+++ b/app/models/concerns/account_header.rb
@@ -20,13 +20,13 @@ module AccountHeader
     has_attached_file :header, styles: ->(f) { header_styles(f) }, convert_options: { all: '-quality 80 -strip' }
     validates_attachment_content_type :header, content_type: IMAGE_MIME_TYPES
     validates_attachment_size :header, less_than: 2.megabytes
+  end
 
-    def header_original_url
-      header.url(:original)
-    end
+  def header_original_url
+    header.url(:original)
+  end
 
-    def header_static_url
-      header_content_type == 'image/gif' ? header.url(:static) : header_original_url
-    end
+  def header_static_url
+    header_content_type == 'image/gif' ? header.url(:static) : header_original_url
   end
 end
diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb
index d51e6643e..c8006bd0b 100644
--- a/app/models/concerns/account_interactions.rb
+++ b/app/models/concerns/account_interactions.rb
@@ -46,82 +46,82 @@ module AccountInteractions
     has_many :muting, -> { order('mutes.id desc') }, through: :mute_relationships, source: :target_account
     has_many :conversation_mutes, dependent: :destroy
     has_many :domain_blocks, class_name: 'AccountDomainBlock', dependent: :destroy
+  end
 
-    def follow!(other_account)
-      active_relationships.find_or_create_by!(target_account: other_account)
-    end
+  def follow!(other_account)
+    active_relationships.find_or_create_by!(target_account: other_account)
+  end
 
-    def block!(other_account)
-      block_relationships.find_or_create_by!(target_account: other_account)
-    end
+  def block!(other_account)
+    block_relationships.find_or_create_by!(target_account: other_account)
+  end
 
-    def mute!(other_account)
-      mute_relationships.find_or_create_by!(target_account: other_account)
-    end
+  def mute!(other_account)
+    mute_relationships.find_or_create_by!(target_account: other_account)
+  end
 
-    def mute_conversation!(conversation)
-      conversation_mutes.find_or_create_by!(conversation: conversation)
-    end
+  def mute_conversation!(conversation)
+    conversation_mutes.find_or_create_by!(conversation: conversation)
+  end
 
-    def block_domain!(other_domain)
-      domain_blocks.find_or_create_by!(domain: other_domain)
-    end
+  def block_domain!(other_domain)
+    domain_blocks.find_or_create_by!(domain: other_domain)
+  end
 
-    def unfollow!(other_account)
-      follow = active_relationships.find_by(target_account: other_account)
-      follow&.destroy
-    end
+  def unfollow!(other_account)
+    follow = active_relationships.find_by(target_account: other_account)
+    follow&.destroy
+  end
 
-    def unblock!(other_account)
-      block = block_relationships.find_by(target_account: other_account)
-      block&.destroy
-    end
+  def unblock!(other_account)
+    block = block_relationships.find_by(target_account: other_account)
+    block&.destroy
+  end
 
-    def unmute!(other_account)
-      mute = mute_relationships.find_by(target_account: other_account)
-      mute&.destroy
-    end
+  def unmute!(other_account)
+    mute = mute_relationships.find_by(target_account: other_account)
+    mute&.destroy
+  end
 
-    def unmute_conversation!(conversation)
-      mute = conversation_mutes.find_by(conversation: conversation)
-      mute&.destroy!
-    end
+  def unmute_conversation!(conversation)
+    mute = conversation_mutes.find_by(conversation: conversation)
+    mute&.destroy!
+  end
 
-    def unblock_domain!(other_domain)
-      block = domain_blocks.find_by(domain: other_domain)
-      block&.destroy
-    end
+  def unblock_domain!(other_domain)
+    block = domain_blocks.find_by(domain: other_domain)
+    block&.destroy
+  end
 
-    def following?(other_account)
-      active_relationships.where(target_account: other_account).exists?
-    end
+  def following?(other_account)
+    active_relationships.where(target_account: other_account).exists?
+  end
 
-    def blocking?(other_account)
-      block_relationships.where(target_account: other_account).exists?
-    end
+  def blocking?(other_account)
+    block_relationships.where(target_account: other_account).exists?
+  end
 
-    def domain_blocking?(other_domain)
-      domain_blocks.where(domain: other_domain).exists?
-    end
+  def domain_blocking?(other_domain)
+    domain_blocks.where(domain: other_domain).exists?
+  end
 
-    def muting?(other_account)
-      mute_relationships.where(target_account: other_account).exists?
-    end
+  def muting?(other_account)
+    mute_relationships.where(target_account: other_account).exists?
+  end
 
-    def muting_conversation?(conversation)
-      conversation_mutes.where(conversation: conversation).exists?
-    end
+  def muting_conversation?(conversation)
+    conversation_mutes.where(conversation: conversation).exists?
+  end
 
-    def requested?(other_account)
-      follow_requests.where(target_account: other_account).exists?
-    end
+  def requested?(other_account)
+    follow_requests.where(target_account: other_account).exists?
+  end
 
-    def favourited?(status)
-      status.proper.favourites.where(account: self).exists?
-    end
+  def favourited?(status)
+    status.proper.favourites.where(account: self).exists?
+  end
 
-    def reblogged?(status)
-      status.proper.reblogs.where(account: self).exists?
-    end
+  def reblogged?(status)
+    status.proper.reblogs.where(account: self).exists?
   end
 end
diff --git a/app/models/concerns/streamable.rb b/app/models/concerns/streamable.rb
index 910736dac..7c9edb8ef 100644
--- a/app/models/concerns/streamable.rb
+++ b/app/models/concerns/streamable.rb
@@ -6,36 +6,38 @@ module Streamable
   included do
     has_one :stream_entry, as: :activity
 
-    def title
-      super
+    after_create do
+      account.stream_entries.create!(activity: self, hidden: hidden?) if needs_stream_entry?
     end
+  end
 
-    def content
-      title
-    end
+  def title
+    super
+  end
 
-    def target
-      super
-    end
+  def content
+    title
+  end
 
-    def object_type
-      :activity
-    end
+  def target
+    super
+  end
 
-    def thread
-      super
-    end
+  def object_type
+    :activity
+  end
 
-    def hidden?
-      false
-    end
+  def thread
+    super
+  end
 
-    def needs_stream_entry?
-      account.local?
-    end
+  def hidden?
+    false
+  end
 
-    after_create do
-      account.stream_entries.create!(activity: self, hidden: hidden?) if needs_stream_entry?
-    end
+  private
+
+  def needs_stream_entry?
+    account.local?
   end
 end
diff --git a/app/models/concerns/targetable.rb b/app/models/concerns/targetable.rb
index 4c335a302..506253bed 100644
--- a/app/models/concerns/targetable.rb
+++ b/app/models/concerns/targetable.rb
@@ -1,11 +1,7 @@
 # frozen_string_literal: true
 
 module Targetable
-  extend ActiveSupport::Concern
-
-  included do
-    def object_type
-      :object
-    end
+  def object_type
+    :object
   end
 end