Class: Thredded::PrivateTopicForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/forms/thredded/private_topic_form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PrivateTopicForm

Returns a new instance of PrivateTopicForm.



22
23
24
25
26
27
28
29
30
31
# File 'app/forms/thredded/private_topic_form.rb', line 22

def initialize(params = {})
  @params = params
  @title = params[:title]
  @category_ids = params[:category_ids] || []
  @user_ids = params[:user_ids] || []
  @user = params[:user] || fail('user is required')
  @locked = params[:locked]
  @sticky = params[:sticky]
  @content = params[:content]
end

Instance Attribute Details

#category_idsObject

Returns the value of attribute category_ids.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def category_ids
  @category_ids
end

#contentObject

Returns the value of attribute content.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def content
  @content
end

#lockedObject

Returns the value of attribute locked.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def locked
  @locked
end

#paramsObject (readonly)

Returns the value of attribute params.



18
19
20
# File 'app/forms/thredded/private_topic_form.rb', line 18

def params
  @params
end

#private_topicObject

Returns the value of attribute private_topic.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def private_topic
  @private_topic
end

#stickyObject

Returns the value of attribute sticky.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def sticky
  @sticky
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def title
  @title
end

#userObject (readonly)

Returns the value of attribute user.



18
19
20
# File 'app/forms/thredded/private_topic_form.rb', line 18

def user
  @user
end

#user_idsObject

Returns the value of attribute user_ids.



9
10
11
# File 'app/forms/thredded/private_topic_form.rb', line 9

def user_ids
  @user_ids
end

Class Method Details

.model_nameObject



33
34
35
# File 'app/forms/thredded/private_topic_form.rb', line 33

def self.model_name
  Thredded::PrivateTopic.model_name
end

Instance Method Details

#postObject



56
57
58
59
60
61
# File 'app/forms/thredded/private_topic_form.rb', line 56

def post
  @post ||= private_topic.posts.build(
    content: content,
    user: non_null_user
  )
end

#saveObject



37
38
39
40
41
42
43
44
45
# File 'app/forms/thredded/private_topic_form.rb', line 37

def save
  return false unless valid?

  ActiveRecord::Base.transaction do
    private_topic.save!
    post.save!
  end
  true
end