Class: SuggestedEdit

Inherits:
ApplicationRecord show all
Includes:
EditsValidations, PostRelated, PostValidations
Defined in:
app/models/suggested_edit.rb

Instance Method Summary collapse

Methods included from EditsValidations

#max_edit_comment_length

Methods included from PostValidations

#maximum_tag_length, #maximum_tags, #maximum_title_length, #no_spaces_in_tags, #required_tags?, #stripped_minimum_body, #stripped_minimum_title, #tags_in_tag_set

Methods inherited from ApplicationRecord

#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/suggested_edit.rb', line 28

def approved?
  !active && accepted
end

#clear_pending_cacheObject



20
21
22
# File 'app/models/suggested_edit.rb', line 20

def clear_pending_cache
  Rails.cache.delete "pending_suggestions/#{post.category_id}"
end

#on_article?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/suggested_edit.rb', line 40

def on_article?
  post.article?
end

#on_question?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/suggested_edit.rb', line 36

def on_question?
  post.question?
end

#pending?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/suggested_edit.rb', line 24

def pending?
  active
end

#rejected?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/suggested_edit.rb', line 32

def rejected?
  !active && !accepted
end

#update_tag_associationsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/suggested_edit.rb', line 46

def update_tag_associations
  return if tags_cache.nil? # Don't update if this doesn't affect tags

  tags_cache.each do |tag_name|
    tag = Tag.find_or_create_by name: tag_name, tag_set: post.category.tag_set
    unless tags.include? tag
      tags << tag
    end
  end

  tags.each do |tag|
    unless tags_cache.include? tag.name
      tags.delete tag
    end
  end
end