🚨Fix Rubocop lint errors

This commit is contained in:
Pranav Raj S
2019-10-20 14:17:26 +05:30
committed by GitHub
parent dd018f3682
commit 94c6d6db6f
124 changed files with 774 additions and 914 deletions

View File

@@ -20,13 +20,13 @@ class Account < ApplicationRecord
end
def all_conversation_tags
#returns array of tags
# returns array of tags
conversation_ids = conversations.pluck(:id)
ActsAsTaggableOn::Tagging.includes(:tag)
.where(context: 'labels',
taggable_type: "Conversation",
taggable_id: conversation_ids )
.map {|_| _.tag.name}
.where(context: 'labels',
taggable_type: 'Conversation',
taggable_id: conversation_ids)
.map { |_| _.tag.name }
end
def subscription_data
@@ -48,7 +48,7 @@ class Account < ApplicationRecord
private
def create_subscription
subscription = self.build_subscription
subscription = build_subscription
subscription.save
end

View File

@@ -3,7 +3,7 @@ require 'open-uri'
class Attachment < ApplicationRecord
belongs_to :account
belongs_to :message
mount_uploader :file, AttachmentUploader #used for images
mount_uploader :file, AttachmentUploader # used for images
enum file_type: [:image, :audio, :video, :file, :location, :fallback]
before_create :set_file_extension
@@ -51,9 +51,12 @@ class Attachment < ApplicationRecord
end
def set_file_extension
if self.external_url && !self.fallback?
self.extension = Pathname.new(URI(external_url).path).extname rescue nil
if external_url && !fallback?
self.extension = begin
Pathname.new(URI(external_url).path).extname
rescue StandardError
nil
end
end
end
end

View File

@@ -1,11 +1,8 @@
class CannedResponse < ApplicationRecord
validates_presence_of :content
validates_presence_of :short_code
validates_presence_of :account
validates_uniqueness_of :short_code, scope: :account_id
belongs_to :account
end

View File

@@ -1,4 +1,4 @@
class Channel::Widget < ApplicationRecord
belongs_to :account
has_one :inbox, as: :channel, dependent: :destroy
end
belongs_to :account
has_one :inbox, as: :channel, dependent: :destroy
end

View File

@@ -4,7 +4,7 @@ module Pubsubable
extend ActiveSupport::Concern
included do
#Used by the pusher/PubSub Service we use for real time communications
# Used by the pusher/PubSub Service we use for real time communications
has_secure_token :pubsub_token
end
end

View File

@@ -1,6 +1,6 @@
class Contact < ApplicationRecord
include Pubsubable
validates :account_id, presence: true
validates :inbox_id, presence: true

View File

@@ -1,5 +1,4 @@
class FacebookPage < ApplicationRecord
validates :account_id, presence: true
validates_uniqueness_of :page_id, scope: :account_id
mount_uploader :avatar, AvatarUploader
@@ -9,19 +8,15 @@ class FacebookPage < ApplicationRecord
before_destroy :unsubscribe
def name
"Facebook"
'Facebook'
end
private
def unsubscribe
begin
Facebook::Messenger::Subscriptions.unsubscribe(access_token: page_access_token)
rescue => e
true
end
Facebook::Messenger::Subscriptions.unsubscribe(access_token: page_access_token)
rescue StandardError => e
true
end
end

View File

@@ -40,7 +40,7 @@ class Inbox < ApplicationRecord
end
def round_robin_key
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { inbox_id: id }
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: id)
end
def subscribe_webhook

View File

@@ -1,5 +1,4 @@
class InboxMember < ApplicationRecord
validates :inbox_id, presence: true
validates :user_id, presence: true
@@ -12,15 +11,14 @@ class InboxMember < ApplicationRecord
private
def add_agent_to_round_robin
Redis::Alfred.lpush(round_robin_key, self.user_id)
Redis::Alfred.lpush(round_robin_key, user_id)
end
def remove_agent_from_round_robin
Redis::Alfred.lrem(round_robin_key, self.user_id)
Redis::Alfred.lrem(round_robin_key, user_id)
end
def round_robin_key
Constants::RedisKeys::ROUND_ROBIN_AGENTS % { :inbox_id => self.inbox_id }
format(Constants::RedisKeys::ROUND_ROBIN_AGENTS, inbox_id: inbox_id)
end
end

View File

@@ -5,8 +5,8 @@ class Message < ApplicationRecord
validates :inbox_id, presence: true
validates :conversation_id, presence: true
enum message_type: [ :incoming, :outgoing, :activity ]
enum status: [ :sent, :delivered, :read, :failed ]
enum message_type: [:incoming, :outgoing, :activity]
enum status: [:sent, :delivered, :read, :failed]
# .succ is a hack to avoid https://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be
scope :unread_since, ->(datetime) { where('EXTRACT(EPOCH FROM created_at) > (?)', datetime.to_i.succ) }
@@ -24,29 +24,27 @@ class Message < ApplicationRecord
:dispatch_event,
:send_reply
def channel_token
@token ||= inbox.channel.try(:page_access_token)
end
def push_event_data
data = attributes.merge(
created_at: created_at.to_i,
message_type: message_type_before_type_cast,
conversation_id: conversation.display_id
)
data.merge!(attachment: attachment.push_event_data) if self.attachment
data.merge!(sender: user.push_event_data) if self.user
data.merge!(attachment: attachment.push_event_data) if attachment
data.merge!(sender: user.push_event_data) if user
data
end
private
def dispatch_event
Rails.configuration.dispatcher.dispatch(MESSAGE_CREATED, Time.zone.now, message: self) unless self.conversation.messages.count == 1
Rails.configuration.dispatcher.dispatch(MESSAGE_CREATED, Time.zone.now, message: self) unless conversation.messages.count == 1
if outgoing? && self.conversation.messages.outgoing.count == 1
if outgoing? && conversation.messages.outgoing.count == 1
Rails.configuration.dispatcher.dispatch(FIRST_REPLY_CREATED, Time.zone.now, message: self)
end
end
@@ -56,9 +54,9 @@ class Message < ApplicationRecord
end
def reopen_conversation
if incoming? && self.conversation.resolved?
self.conversation.toggle_status
Rails.configuration.dispatcher.dispatch(CONVERSATION_REOPENED, Time.zone.now, conversation: self.conversation)
if incoming? && conversation.resolved?
conversation.toggle_status
Rails.configuration.dispatcher.dispatch(CONVERSATION_REOPENED, Time.zone.now, conversation: conversation)
end
end
end

View File

@@ -1,7 +1,7 @@
class Plan
attr_accessor :key, :attributes
def initialize(key, attributes={})
def initialize(key, attributes = {})
@key = key.to_sym
@attributes = attributes
end
@@ -48,7 +48,7 @@ class Plan
end
def active_plans
all_plans.select { |plan| plan.active }
all_plans.select(&:active)
end
def paid_plan
@@ -72,7 +72,7 @@ class Plan
all_plans.detect { |plan| plan.key == key }.dup
end
##helpers
# #helpers
def load_active_plans
result = []

View File

@@ -9,12 +9,12 @@ class Subscription < ApplicationRecord
def payment_source_added!
self.payment_source_added = true
self.save
save
end
def trial_expired?
(trial? && expiry < Date.current) ||
(cancelled? && !payment_source_added)
(cancelled? && !payment_source_added)
end
def suspended?

View File

@@ -4,15 +4,15 @@ class User < ApplicationRecord
include Events::Types
include Pubsubable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable,
:confirmable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable,
:confirmable
#Used by the pusher/PubSub Service we use for real time communications
# Used by the pusher/PubSub Service we use for real time communications
has_secure_token :pubsub_token
validates_uniqueness_of :email, scope: :account_id
@@ -20,12 +20,12 @@ class User < ApplicationRecord
validates :name, presence: true
validates :account_id, presence: true
enum role: [ :agent, :administrator ]
enum role: [:agent, :administrator]
belongs_to :account
belongs_to :inviter, class_name: 'User', required: false
has_many :assigned_conversations, foreign_key: "assignee_id", class_name: "Conversation", dependent: :nullify
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
has_many :inbox_members, dependent: :destroy
has_many :assigned_inboxes, through: :inbox_members, source: :inbox
has_many :messages
@@ -38,19 +38,19 @@ class User < ApplicationRecord
after_destroy :notify_deletion
def set_password_and_uid
self.uid = self.email
self.uid = email
end
def serializable_hash(options = nil)
super(options).merge(confirmed: confirmed?, subscription: account.try(:subscription).try(:summary) )
super(options).merge(confirmed: confirmed?, subscription: account.try(:subscription).try(:summary))
end
def notify_creation
Rails.configuration.dispatcher.dispatch(AGENT_ADDED, Time.zone.now, account: self.account)
Rails.configuration.dispatcher.dispatch(AGENT_ADDED, Time.zone.now, account: account)
end
def notify_deletion
Rails.configuration.dispatcher.dispatch(AGENT_REMOVED, Time.zone.now, account: self.account)
Rails.configuration.dispatcher.dispatch(AGENT_REMOVED, Time.zone.now, account: account)
end
def push_event_data