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



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_versionObject



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

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

#create_processing_versionObject



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_versionObject



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

def next_version
  preview_version || processing_version || processing_failed_version
end

#preview_versionObject



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

def preview_version
	versions.preview.last
end

#processing_failed_versionObject



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

def processing_failed_version
  versions.processing_failed.last
end

#processing_versionObject



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

def processing_version
  versions.processing.last
end

#serializeObject



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

Returns:

  • (Boolean)


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

def should_generate_new_friendly_id?
  new_record? || title_changed?
end

#tagsObject



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

def tags
  .map(&:label)
end