Class: Pulitzer::PostTypeVersionsController::Create

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

Instance Method Summary collapse

Constructor Details

#initialize(params, create_post = true) ⇒ Create

Returns a new instance of Create.



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

def initialize(params, create_post=true)
  @params = params.to_h.to_hash.symbolize_keys
  @create_post = create_post
end

Instance Method Details

#callObject



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

def call
  @ptv = Pulitzer::PostTypeVersion.new(@params)
  @post_type = @ptv.post_type
  last_version_number = @post_type.post_type_versions.maximum(:version_number) || 0
  this_version_number = last_version_number + 1
  @ptv.version_number = this_version_number
  @ptv.save
  ::Pulitzer::CreateSingletonPost.new(@ptv).call if @create_post
  @ptv
end