Class: Pulitzer::PostTypeVersionsController::ImportPost

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

Instance Method Summary collapse

Constructor Details

#initialize(post_type_version, params) ⇒ ImportPost

Returns a new instance of ImportPost.



3
4
5
# File 'app/interactions/pulitzer/post_type_versions_controller/import_post.rb', line 3

def initialize(post_type_version, params)
  @post_type_version, @params = post_type_version, params
end

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/interactions/pulitzer/post_type_versions_controller/import_post.rb', line 7

def call
  import_json = @params[:import_json].read
  post = Pulitzer::Post.new
  post.from_json import_json
  post.post_type_version = @post_type_version
  if Pulitzer::Post.where(title: post.title).to_a.any?{|other_post|
    (other_post.post_type_version_id == post.post_type_version_id)}
    post.title += ' (cloned)'
  end
  post.save
  post
end