Repository URL to install this package:
|
Version:
2.23.0 ▾
|
module JPlatform
module ProjectConcern
extend ActiveSupport::Concern
include PlatformConcern
included do
schema do
string :name, :status, :client_id, :description, :is_closed, :is_suspended
end
belongs_to :client, class_name: "#{@module_name}::Client"
has_many :social_accounts, class_name: 'SocialAccount'
has_many :project_memberships, class_name: "#{@module_name}::ProjectMembership"
has_many :project_social_accounts, class_name: "#{@module_name}::ProjectSocialAccount"
has_many :client_memberships, class_name: "#{@module_name}::ClientMembership"
validates :name, presence: { message: I18n.t('messages.error.project_name') }
def social_accounts
attributes[:social_accounts] || project_social_accounts.map(&:social_account)
end
end
module ClassMethods
def find(*args)
project = nil
last_updated_at = Rails.cache.fetch("j_platform_project_#{args[0]}_last_updated_at", race_condition_ttl: 5)
if last_updated_at
project = Rails.cache.fetch("j_platform_project_#{args}_#{last_updated_at}", race_condition_ttl: 5)
end
unless project
project = super
Rails.cache.write("j_platform_project_#{args}_#{project.updated_at}", project, expires_in: 10.seconds)
Rails.cache.write("j_platform_project_#{project.id}_last_updated_at", project.updated_at, expires_in: 10.seconds)
end
project
end
end
def post_social_accounts
(social_accounts||[]).select { |sa| sa.postable }
end
def members
client_memberships.map(&:user)
end
def to_s; name end
end
end