module ActsAsCommentableMore::Helpers::Comment::InstanceMethodsHelper

Private Class Methods

find_comments_by_user(user, role = nil) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 32
def find_comments_by_user(user, role = nil)
  attr_finder = { user: user }
  attr_finder.merge!(role: role) if role.present?
  where(attr_finder).order(created_at: :desc)
end

Private Instance Methods

comment_define_can_change_role_of(comment_model, commentable_name) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 43
def comment_define_can_change_role_of(comment_model, commentable_name)
  comment_model.redefine_method("can_change_role?") do |role|
    commentable_class = send(commentable_name).class
    limit_role = commentable_class.aacm_commentable_options[:comment_roles]
    limit_role.include?(role)
  end
  comment_model.send(:private, "can_change_role?".to_sym)
end
comment_define_class_method(comment_model) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 26
def comment_define_class_method(comment_model)
  
  comment_model.class_eval do

    class << self

      def find_comments_by_user(user, role = nil)
        attr_finder = { user: user }
        attr_finder.merge!(role: role) if role.present?
        where(attr_finder).order(created_at: :desc)
      end

    end
  end

end
comment_define_instance_method(comment_model) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 8
def comment_define_instance_method(comment_model)

  comment_model.class_eval do
  
    redefine_method :related_attributes= do |value|
      previous_data = @related_attributes || {} 
      @related_attributes = previous_data.merge(value)
      write_attribute(:related_attributes, @related_attributes)
    end
  
    redefine_method :related_attributes do
      read_attribute(:related_attributes).symbolize_keys
    end
  
  end

end
comment_define_is_role?(comment_model, role) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 52
def comment_define_is_role?(comment_model, role)
  comment_model.redefine_method("is_#{role}?") do
    raise(NoMethodError, "undefined method 'is_" + role + "?'") unless can_change_role?(role)
    self.role == role
  end
end
comment_define_to_role(comment_model, role) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 59
def comment_define_to_role(comment_model, role)
  comment_model.redefine_method("to_#{role}") do
    raise(NoMethodError, "undefined method 'is_" + role + "?'") unless can_change_role?(role)
    self.role = role
    self
  end
end
comment_define_to_role!(comment_model, role) click to toggle source
# File lib/acts_as_commentable_more/helpers/comment/instance_methods_helper.rb, line 67
def comment_define_to_role!(comment_model, role)
  comment_model.redefine_method("to_#{role}!") do
    raise(NoMethodError, "undefined method 'is_" + role + "?'") unless can_change_role?(role)
    self.update(role: role)
    self
  end
end