Class: PostManager
- Inherits:
-
Object
- Object
- PostManager
- Defined in:
- app/services/post_manager.rb
Overview
Manager for handling post-related cases
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
Instance Method Summary collapse
- #category_name ⇒ Object
- #category_path ⇒ Object
- #edit_path ⇒ Object
- #empty_category_path ⇒ Object
- #entity=(entity) ⇒ Object
-
#initialize(entity, locale = I18n.locale) ⇒ PostManager
constructor
A new instance of PostManager.
- #parsed_body ⇒ Object
- #post_path ⇒ Object
- #tagged_path(tag_name) ⇒ Object
Constructor Details
#initialize(entity, locale = I18n.locale) ⇒ PostManager
Returns a new instance of PostManager.
9 10 11 12 |
# File 'app/services/post_manager.rb', line 9 def initialize(entity, locale = I18n.locale) self.entity = entity self.locale = locale end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'app/services/post_manager.rb', line 5 def locale @locale end |
Class Method Details
.editor?(user, type) ⇒ Boolean
16 17 18 19 20 21 22 |
# File 'app/services/post_manager.rb', line 16 def self.editor?(user, type) return true if UserPrivilege.user_has_privilege?(user, :chief_editor) type = PostType.find_by(slug: type) unless type.is_a?(PostType) EditorialMember.find_by(user: user)&.post_type?(type) end |
.enclosures(post) ⇒ Object
25 26 27 28 29 |
# File 'app/services/post_manager.rb', line 25 def self.enclosures(post) post.parsed_body.scan(/<img[^>]+>/).map do |image| image.scan(/src="([^"]+)"/)[0][0] end end |
Instance Method Details
#category_name ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/post_manager.rb', line 64 def category_name if @entity.is_a?(Post) if @entity.post_category.nil? @entity.post_type.default_category_name else @entity.post_categories.map(&:text_for_link) end else @entity.text_for_link end end |
#category_path ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/services/post_manager.rb', line 56 def category_path postfix = '' suffix = @entity.is_a?(Post) ? @entity.post_category : @entity postfix += "/#{suffix.long_slug}" unless suffix.nil? empty_category_path + postfix end |
#edit_path ⇒ Object
47 48 49 |
# File 'app/services/post_manager.rb', line 47 def edit_path "#{@prefix}/posts/#{@entity.id}/edit" if @entity.is_a?(Post) end |
#empty_category_path ⇒ Object
76 77 78 |
# File 'app/services/post_manager.rb', line 76 def empty_category_path "#{@prefix}/#{@url_part}" end |
#entity=(entity) ⇒ Object
32 33 34 35 36 37 |
# File 'app/services/post_manager.rb', line 32 def entity=(entity) @entity = entity @body = entity.body.to_s if @entity.is_a?(Post) @prefix = locale.nil? || locale == I18n.default_locale ? '' : "/#{locale}" @url_part = entity.post_type.url_part end |
#parsed_body ⇒ Object
39 40 41 |
# File 'app/services/post_manager.rb', line 39 def parsed_body PostParser.new(@entity).parsed_body if @entity.is_a?(Post) end |
#post_path ⇒ Object
43 44 45 |
# File 'app/services/post_manager.rb', line 43 def post_path "#{@prefix}/#{@url_part}/#{@entity.id}-#{@entity.slug}" if @entity.is_a?(Post) end |
#tagged_path(tag_name) ⇒ Object
52 53 54 |
# File 'app/services/post_manager.rb', line 52 def tagged_path(tag_name) "#{@prefix}/#{@url_part}/tagged/#{CGI.escape(tag_name)}" end |