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.



17
18
19
# File 'app/models/pulitzer/post.rb', line 17

def new_preview_version
  @new_preview_version
end

Instance Method Details

#content_element(label) ⇒ Object



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

def content_element(label)
  if content_elements
    self.content_elements.find_by(label: label)
  end
end

#create_preview_versionObject



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

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

#create_processing_versionObject



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

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

#next_versionObject



49
50
51
# File 'app/models/pulitzer/post.rb', line 49

def next_version
  preview_version || processing_version || processing_failed_version
end

#preview_versionObject



37
38
39
# File 'app/models/pulitzer/post.rb', line 37

def preview_version
	versions.preview.last
end

#processing_failed_versionObject



45
46
47
# File 'app/models/pulitzer/post.rb', line 45

def processing_failed_version
  versions.processing_failed.last
end

#processing_versionObject



41
42
43
# File 'app/models/pulitzer/post.rb', line 41

def processing_version
  versions.processing.last
end

#serializeObject



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

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

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/pulitzer/post.rb', line 33

def should_generate_new_friendly_id?
  new_record? || title_changed?
end

#tagsObject



23
24
25
# File 'app/models/pulitzer/post.rb', line 23

def tags
  .map(&:label)
end