Class: Pressroom::Post

Inherits:
ApplicationRecord show all
Includes:
Authorable, Scoped, Sluggable
Defined in:
app/models/pressroom/post.rb

Constant Summary collapse

SCHEMA_VERSION =
1
EMPTY_DOCUMENT =
{ "schema_version" => SCHEMA_VERSION, "blocks" => [] }.freeze
EXCERPT_LENGTH =
200

Constants included from Sluggable

Sluggable::FALLBACK_SLUG

Constants included from Scoped

Scoped::NO_SCOPE_ID, Scoped::NO_SCOPE_TYPE

Instance Method Summary collapse

Methods included from Scoped

id_for, #scope, #scope=, #scoped?, type_for

Instance Method Details

#blocksObject



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

def blocks
  Array(content.is_a?(Hash) ? content["blocks"] : nil)
end

#content=(value) ⇒ Object

Normalizes anything the caller hands us into a versioned document.



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

def content=(value)
  super(normalize_document(value))
end

#published?Boolean

Live to the public right now, as opposed to merely flagged published.

Returns:

  • (Boolean)


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

def published?
  status == "published" && published_at.present? && published_at <= Time.current
end

#tag_namesObject



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

def tag_names
  tags.map(&:name)
end

#tag_names=(value) ⇒ Object

Accepts an array of names or a comma separated string, and replaces the whole tag set.



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

def tag_names=(value)
  names = value.is_a?(String) ? value.split(",") : Array(value)
  self.tags = Pressroom::Tag.for_names(names)
end