Class: Post

Inherits:
ApplicationRecord show all
Includes:
CommentableItem, HasOwner, Toggleable, VotableItem
Defined in:
app/models/post.rb

Constant Summary collapse

TITLE_LIMIT =
140
SLUG_LIMIT =
200
SLUG_PATTERN =
/\A[a-z0-9]+[-_.a-z0-9]*[a-z0-9]+\z/
LEAD_LIMIT =
350
BODY_LIMIT =
50000
META_LIMIT =
250
ALT_LIMIT =
200
PER_PAGE =
10

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.creation_parametersObject



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

def self.creation_parameters
  entity_parameters + %i(post_type_id)
end

.entity_parametersObject



66
67
68
69
70
71
72
73
74
# File 'app/models/post.rb', line 66

def self.entity_parameters
  main_data   = %i(post_category_id title slug lead body visible translation region_id)
  image_data  = %i(image image_alt_text image_name image_author_name image_author_link)
     = %i(source_name source_link meta_title meta_description meta_keywords)
  flags_data  = %i(show_owner allow_comments)
  author_data = %i(author_name author_title author_url)

  main_data + image_data +  + author_data + flags_data
end

.page_for_administration(page = 1) ⇒ Object

Parameters:

  • page (Integer) (defaults to: 1)


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

def self.page_for_administration(page = 1)
  recent.page(page).per(PER_PAGE)
end

.page_for_visitors(page = 1) ⇒ Object

Parameters:

  • page (Integer) (defaults to: 1)


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

def self.page_for_visitors(page = 1)
  list_for_visitors.page(page).per(PER_PAGE)
end

Instance Method Details

#editable_by?(user) ⇒ Boolean

Parameters:

  • user (User)

Returns:

  • (Boolean)


81
82
83
# File 'app/models/post.rb', line 81

def editable_by?(user)
  owned_by?(user) || UserPrivilege.user_has_privilege?(user, :chief_editor)
end

#has_image_data?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/post.rb', line 85

def has_image_data?
  !image_name.blank? || !image_author_name.blank? || !image_author_link.blank?
end

#has_source_data?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'app/models/post.rb', line 89

def has_source_data?
  !source_name.blank? || !source_link.blank?
end