cosmetical cleanup of models
This commit is contained in:
parent
2a4359a572
commit
841e4fbd08
18 changed files with 108 additions and 226 deletions
|
@ -2,39 +2,26 @@ require 'carrierwave/orm/activerecord'
|
|||
require 'file_size_validator'
|
||||
|
||||
class Note < ActiveRecord::Base
|
||||
mount_uploader :attachment, AttachmentUploader
|
||||
attr_accessible :note, :noteable, :noteable_id, :noteable_type, :project_id,
|
||||
:attachment, :line_code
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :noteable, polymorphic: true
|
||||
belongs_to :author,
|
||||
class_name: "User"
|
||||
belongs_to :author, class_name: "User"
|
||||
|
||||
delegate :name,
|
||||
to: :project,
|
||||
prefix: true
|
||||
|
||||
delegate :name,
|
||||
:email,
|
||||
to: :author,
|
||||
prefix: true
|
||||
delegate :name, to: :project, prefix: true
|
||||
delegate :name, :email, to: :author, prefix: true
|
||||
|
||||
attr_accessor :notify
|
||||
attr_accessor :notify_author
|
||||
|
||||
validates_presence_of :project
|
||||
|
||||
validates :note,
|
||||
presence: true,
|
||||
length: { within: 0..5000 }
|
||||
|
||||
validates :attachment,
|
||||
file_size: {
|
||||
maximum: 10.megabytes.to_i
|
||||
}
|
||||
validates :note, presence: true, length: { within: 0..5000 }
|
||||
validates :attachment, file_size: { maximum: 10.megabytes.to_i }
|
||||
|
||||
scope :common, where(noteable_id: nil)
|
||||
|
||||
scope :today, where("created_at >= :date", date: Date.today)
|
||||
scope :last_week, where("created_at >= :date", date: (Date.today - 7.days))
|
||||
scope :since, lambda { |day| where("created_at >= :date", date: (day)) }
|
||||
|
@ -42,14 +29,13 @@ class Note < ActiveRecord::Base
|
|||
scope :inc_author_project, includes(:project, :author)
|
||||
scope :inc_author, includes(:author)
|
||||
|
||||
mount_uploader :attachment, AttachmentUploader
|
||||
|
||||
def self.create_status_change_note(noteable, author, status)
|
||||
create({ noteable: noteable,
|
||||
project: noteable.project,
|
||||
author: author,
|
||||
note: "_Status changed to #{status}_" },
|
||||
without_protection: true)
|
||||
create({
|
||||
noteable: noteable,
|
||||
project: noteable.project,
|
||||
author: author,
|
||||
note: "_Status changed to #{status}_"
|
||||
}, without_protection: true)
|
||||
end
|
||||
|
||||
def notify
|
||||
|
@ -114,6 +100,7 @@ class Note < ActiveRecord::Base
|
|||
note.start_with?('-1') || note.start_with?(':-1:')
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: notes
|
||||
|
@ -129,4 +116,3 @@ end
|
|||
# attachment :string(255)
|
||||
# line_code :string(255)
|
||||
#
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue