Class: Pulitzer::Post

Inherits:
ActiveRecord::Base
  • Object
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

Instance Method Summary collapse

Instance Attribute Details

#new_preview_versionObject

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



21
22
23
# File 'app/models/pulitzer/post.rb', line 21

def active_version!
  versions.find_by!(status: Pulitzer::Version.statuses[:active])
end

#create_preview_versionObject



68
69
70
# File 'app/models/pulitzer/post.rb', line 68

def create_preview_version
  versions.create(status: :preview)
end

#create_processing_versionObject



72
73
74
# File 'app/models/pulitzer/post.rb', line 72

def create_processing_version
  versions.create(status: :processing)
end

#get_active_version!Object



44
45
46
47
48
49
50
# File 'app/models/pulitzer/post.rb', line 44

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



33
34
35
36
37
38
39
40
41
42
# File 'app/models/pulitzer/post.rb', line 33

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_versionObject



64
65
66
# File 'app/models/pulitzer/post.rb', line 64

def next_version
  preview_version || processing_version || processing_failed_version
end

#preview_versionObject



52
53
54
# File 'app/models/pulitzer/post.rb', line 52

def preview_version
	versions.preview.last
end

#processing_failed_versionObject



60
61
62
# File 'app/models/pulitzer/post.rb', line 60

def processing_failed_version
  versions.processing_failed.last
end

#processing_versionObject



56
57
58
# File 'app/models/pulitzer/post.rb', line 56

def processing_version
  versions.processing.last
end

#serializeObject



76
77
78
79
# File 'app/models/pulitzer/post.rb', line 76

def serialize
  self.attributes.merge \
    new_preview_version: self.new_preview_version
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/pulitzer/post.rb', line 29

def should_generate_new_friendly_id?
  new_record? || title_changed?
end

#tagsObject



25
26
27
# File 'app/models/pulitzer/post.rb', line 25

def tags
  .map(&:label)
end