-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathedition.rb
More file actions
42 lines (31 loc) · 1.03 KB
/
edition.rb
File metadata and controls
42 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Block
class Edition < ApplicationRecord
self.table_name = "block_editions"
include ::Edition::HasLeadOrganisation
belongs_to :document, class_name: "Block::Document", foreign_key: :block_document_id, inverse_of: :editions
validates :title, presence: true
validate :title_contains_alphanumeric_chars
before_validation :set_document_sluggable_string, on: :create
# Abstract method to be implemented by subclasses
# Returns a hash representation of the edition's details
def details
raise NotImplementedError, "Subclasses must implement #details method"
end
def state
:draft
end
def creator
User.first
end
private
def set_document_sluggable_string
return unless document.present? && document.new_record?
document.sluggable_string = title if document.sluggable_string.blank?
end
def title_contains_alphanumeric_chars
if title.present? && title !~ /[a-z0-9]+/i
errors.add(:title, :alphanumeric)
end
end
end
end