Module: Inkwell::ActsAsInkwellPost::InstanceMethods

Includes:
Constants
Defined in:
lib/acts_as_inkwell_post/base.rb

Instance Method Summary collapse

Instance Method Details

#comment_countObject



60
61
62
63
# File 'lib/acts_as_inkwell_post/base.rb', line 60

def comment_count
  users_ids_who_comment_it = ActiveSupport::JSON.decode self.users_ids_who_comment_it
  users_ids_who_comment_it.size
end

#commentline(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/acts_as_inkwell_post/base.rb', line 36

def commentline(options = {})
  options.symbolize_keys!
  last_shown_comment_id = options[:last_shown_comment_id]
  limit = options[:limit] || 10
  for_user = options[:for_user]

  if last_shown_comment_id
    comments = ::Inkwell::Comment.where(:topmost_obj_id => self.id, :topmost_obj_type => ItemTypes::POST).where("created_at < ?", Inkwell::Comment.find(last_shown_comment_id).created_at).order("created_at DESC").limit(limit)
  else
    comments = ::Inkwell::Comment.where(:topmost_obj_id => self.id, :topmost_obj_type => ItemTypes::POST).order("created_at DESC").limit(limit)
  end

  if for_user
    user_class = Object.const_get ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
    raise "for_user param should be a #{user_class.to_s} but it is #{for_user.class.to_s}" unless for_user.class == user_class
    comments.each do |comment|
      comment.is_reblogged = for_user.reblog? comment
      comment.is_favorited = for_user.favorite? comment
    end
  end

  comments.reverse!
end

#communities_rowObject



75
76
77
# File 'lib/acts_as_inkwell_post/base.rb', line 75

def communities_row
  ActiveSupport::JSON.decode self.communities_ids
end

#favorite_countObject



65
66
67
68
# File 'lib/acts_as_inkwell_post/base.rb', line 65

def favorite_count
  users_ids_who_favorite_it = ActiveSupport::JSON.decode self.users_ids_who_favorite_it
  users_ids_who_favorite_it.size
end

#reblog_countObject



70
71
72
73
# File 'lib/acts_as_inkwell_post/base.rb', line 70

def reblog_count
  users_ids_who_reblog_it = ActiveSupport::JSON.decode self.users_ids_who_reblog_it
  users_ids_who_reblog_it.size
end