Class: Pulitzer::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Pulitzer::Post
- 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
-
#new_preview_version ⇒ Object
Returns the value of attribute new_preview_version.
Instance Method Summary collapse
- #active_version! ⇒ Object
- #create_preview_version ⇒ Object
- #create_processing_version ⇒ Object
- #get_active_version! ⇒ Object
- #get_preview_version! ⇒ Object
- #next_version ⇒ Object
- #preview_version ⇒ Object
- #processing_failed_version ⇒ Object
- #processing_version ⇒ Object
- #serialize ⇒ Object
- #should_generate_new_friendly_id? ⇒ Boolean
- #tags ⇒ Object
Instance Attribute Details
#new_preview_version ⇒ Object
Returns the value of attribute new_preview_version.
15 16 17 |
# File 'app/models/pulitzer/post.rb', line 15 def new_preview_version @new_preview_version end |
Instance Method Details
#active_version! ⇒ Object
22 23 24 |
# File 'app/models/pulitzer/post.rb', line 22 def active_version! versions.find_by!(status: Pulitzer::Version.statuses[:active]) end |
#create_preview_version ⇒ Object
69 70 71 |
# File 'app/models/pulitzer/post.rb', line 69 def create_preview_version versions.create(status: :preview) end |
#create_processing_version ⇒ Object
73 74 75 |
# File 'app/models/pulitzer/post.rb', line 73 def create_processing_version versions.create(status: :processing) end |
#get_active_version! ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/pulitzer/post.rb', line 45 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
34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/pulitzer/post.rb', line 34 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
65 66 67 |
# File 'app/models/pulitzer/post.rb', line 65 def next_version preview_version || processing_version || processing_failed_version end |
#preview_version ⇒ Object
53 54 55 |
# File 'app/models/pulitzer/post.rb', line 53 def preview_version versions.preview.last end |
#processing_failed_version ⇒ Object
61 62 63 |
# File 'app/models/pulitzer/post.rb', line 61 def processing_failed_version versions.processing_failed.last end |
#processing_version ⇒ Object
57 58 59 |
# File 'app/models/pulitzer/post.rb', line 57 def processing_version versions.processing.last end |
#serialize ⇒ Object
77 78 79 80 |
# File 'app/models/pulitzer/post.rb', line 77 def serialize self.attributes.merge \ new_preview_version: self.new_preview_version end |
#should_generate_new_friendly_id? ⇒ Boolean
30 31 32 |
# File 'app/models/pulitzer/post.rb', line 30 def should_generate_new_friendly_id? new_record? || title_changed? end |
#tags ⇒ Object
26 27 28 |
# File 'app/models/pulitzer/post.rb', line 26 def .map(&:label) end |