Class: Blogo::CreatePostService

Inherits:
BasePostService show all
Defined in:
app/services/blogo/create_post_service.rb

Constant Summary

Constants inherited from BasePostService

BasePostService::JUMP_BREAK

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, params) ⇒ CreatePostService

Returns a new instance of CreatePostService.



5
6
7
8
9
# File 'app/services/blogo/create_post_service.rb', line 5

def initialize(user, params)
  @post        = user.posts.build
  @tags_string = params.delete(:tags_string)
  @post_attrs  = params
end

Instance Attribute Details

#postObject (readonly)

Returns the value of attribute post.



3
4
5
# File 'app/services/blogo/create_post_service.rb', line 3

def post
  @post
end

Instance Method Details

#create!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/blogo/create_post_service.rb', line 11

def create!
  assign_attributes
  return false unless @post.valid?

  @post.transaction do
    @post.save!
    set_tags!(@tags_string)

    # Save tags_string
    # TODO: fix to have 1 save
    @post.save!
  end

  true
end