Class: Pulitzer::CreateSingletonPost

Inherits:
Object
  • Object
show all
Defined in:
app/interactions/pulitzer/create_singleton_post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post_type, title) ⇒ CreateSingletonPost

Returns a new instance of CreateSingletonPost.



4
5
6
7
# File 'app/interactions/pulitzer/create_singleton_post.rb', line 4

def initialize(post_type, title)
  self.post_type = post_type
  self.title = title
end

Instance Attribute Details

#post_typeObject

Returns the value of attribute post_type.



2
3
4
# File 'app/interactions/pulitzer/create_singleton_post.rb', line 2

def post_type
  @post_type
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'app/interactions/pulitzer/create_singleton_post.rb', line 2

def title
  @title
end

Instance Method Details

#callObject



9
10
11
12
13
14
# File 'app/interactions/pulitzer/create_singleton_post.rb', line 9

def call
  if post_type.singular? && !post_type.posts.any?
    singleton_post = post_type.posts.create(title: title)
    Pulitzer::CreatePostContentElements.new(singleton_post).call
  end
end