Class: PostManager

Inherits:
Object
  • Object
show all
Defined in:
app/services/post_manager.rb

Direct Known Subclasses

ArticleHandler, BlogPostHandler, NewsHandler

Defined Under Namespace

Classes: ArticleHandler, BlogPostHandler, NewsHandler

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, locale = I18n.locale) ⇒ PostManager

Returns a new instance of PostManager.

Parameters:

  • entity (Post)
  • locale (Symbol|String) (defaults to: I18n.locale)


4
5
6
7
8
# File 'app/services/post_manager.rb', line 4

def initialize(entity, locale = I18n.locale)
  @entity = entity
  @body   = entity.body.to_s
  @prefix = locale.nil? ? '' : "/#{locale}"
end

Class Method Details

.handler(entity, locale = I18n.locale) ⇒ Object

Parameters:

  • entity (Post)
  • locale (Symbol|String) (defaults to: I18n.locale)


12
13
14
15
16
# File 'app/services/post_manager.rb', line 12

def self.handler(entity, locale = I18n.locale)
  handler_name  = "post_manager/#{entity.post_type.slug}_handler".classify
  handler_class = handler_name.safe_constantize || PostManager
  handler_class.new(entity, locale)
end

Instance Method Details

#category_path(category) ⇒ Object

Parameters:



31
32
33
# File 'app/services/post_manager.rb', line 31

def category_path(category)
  "#{@prefix}/posts/#{category.long_slug}"
end

#edit_pathObject



26
27
28
# File 'app/services/post_manager.rb', line 26

def edit_path
  "#{@prefix}/posts/#{@entity.id}/edit"
end

#parsed_bodyObject



18
19
20
# File 'app/services/post_manager.rb', line 18

def parsed_body
  @body.gsub(/<script/, '&lt;script')
end

#post_pathObject



22
23
24
# File 'app/services/post_manager.rb', line 22

def post_path
  "#{@prefix}/posts/#{@entity.id}"
end