Class: Pulitzer::Post
- Inherits:
-
ApplicationRecord
show all
- Extended by:
- FriendlyId
- Includes:
- ForeignOffice::Broadcaster
- Defined in:
- app/models/pulitzer/post.rb
Constant Summary
collapse
- TAG_MODELS =
["Pulitzer::Tag"] + Pulitzer.tagging_models
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
assoc_name, attrs_name, convert_hash_to_nested
Instance Attribute Details
#new_preview_version ⇒ Object
Returns the value of attribute new_preview_version.
16
17
18
|
# File 'app/models/pulitzer/post.rb', line 16
def new_preview_version
@new_preview_version
end
|
Class Method Details
.convert_nested_assoc(json_hash) ⇒ Object
32
33
34
35
36
37
38
|
# File 'app/models/pulitzer/post.rb', line 32
def self.convert_nested_assoc(json_hash)
this_array = json_hash.has_key?(attrs_name) ? json_hash[attrs_name] : [json_hash]
this_array.map!{|p_attrs|
new_attrs = Pulitzer::Version.convert_hash_to_nested p_attrs
}
json_hash
end
|
.export_config ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'app/models/pulitzer/post.rb', line 23
def self.export_config
{
except: [:id, :post_type_version_id, :created_at, :updated_at, :slug],
include: {
versions: Version.export_config
}
}
end
|
Instance Method Details
#active_version! ⇒ Object
40
41
42
|
# File 'app/models/pulitzer/post.rb', line 40
def active_version!
versions.find_by!(status: Pulitzer::Version.statuses[:active])
end
|
#clonable_versions ⇒ Object
44
45
46
|
# File 'app/models/pulitzer/post.rb', line 44
def clonable_versions
versions.where(status: ['active','preview'])
end
|
#create_preview_version ⇒ Object
91
92
93
|
# File 'app/models/pulitzer/post.rb', line 91
def create_preview_version
versions.create(status: :preview)
end
|
#create_processing_version ⇒ Object
95
96
97
|
# File 'app/models/pulitzer/post.rb', line 95
def create_processing_version
versions.create(status: :processing)
end
|
#editor_title ⇒ Object
99
100
101
102
103
104
105
|
# File 'app/models/pulitzer/post.rb', line 99
def editor_title
if post_type_version.published?
title
else
title + " version #{post_type_version.version_number}"
end
end
|
#get_active_version! ⇒ Object
67
68
69
70
71
72
73
|
# File 'app/models/pulitzer/post.rb', line 67
def get_active_version!
if active_version.present?
return active_version
else
raise Pulitzer::VersionMissingError.new("We couldn't find that page. It looks like we no longer offer that.")
end
end
|
#get_preview_version! ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'app/models/pulitzer/post.rb', line 56
def get_preview_version!
this_version = versions.preview.last
if this_version.present?
return this_version
elsif versions.processing.any?
raise Pulitzer::VersionProcessingError.new("That version is still processing, it will be done soon." )
else
raise Pulitzer::VersionMissingError.new("We couldn't find a preview for that post, check with your system administrator to see how this happened.")
end
end
|
#next_version ⇒ Object
87
88
89
|
# File 'app/models/pulitzer/post.rb', line 87
def next_version
preview_version || processing_version || processing_failed_version
end
|
#preview_version ⇒ Object
75
76
77
|
# File 'app/models/pulitzer/post.rb', line 75
def preview_version
versions.preview.last
end
|
#processing_failed_version ⇒ Object
83
84
85
|
# File 'app/models/pulitzer/post.rb', line 83
def processing_failed_version
versions.processing_failed.last
end
|
#processing_version ⇒ Object
79
80
81
|
# File 'app/models/pulitzer/post.rb', line 79
def processing_version
versions.processing.last
end
|
#serialize ⇒ Object
107
108
109
110
|
# File 'app/models/pulitzer/post.rb', line 107
def serialize
self.attributes.merge \
new_preview_version: self.new_preview_version
end
|
#should_generate_new_friendly_id? ⇒ Boolean
52
53
54
|
# File 'app/models/pulitzer/post.rb', line 52
def should_generate_new_friendly_id?
new_record? || title_changed?
end
|
48
49
50
|
# File 'app/models/pulitzer/post.rb', line 48
def tags
post_tags.map(&:label)
end
|