Sha256: e1a0b5b40134e4ec90ed41fc4713d9181db28e720c1d97bc0a9c2546b5a80f95

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

module ActsAsCommentableMore
  module Helpers
    module Comment
      module MethodsHelper

        private

        def define_can_change_role_of(commentable_name)
          comment_model.redefine_method("can_change_role?") do |role|
            commentable_class = send(commentable_name).class
            limit_role = commentable_class.comment_roles
            limit_role.include?(role.to_sym)
          end
          comment_model.send(:private, "can_change_role?".to_sym)
        end

        def define_is_role?(role)
          comment_model.redefine_method("is_#{role}?") do
            raise(NoMethodError, "undefined method 'is_" + role.to_s + "?'") unless can_change_role?(role.to_s)
            self.role == role.to_s
          end
        end

        def define_to_role(role)
          comment_model.redefine_method("to_#{role}") do
            raise(NoMethodError, "undefined method 'is_" + role.to_s + "?'") unless can_change_role?(role.to_s)
            self.role = role.to_s
            self
          end
        end

        def define_to_role!(role)
          comment_model.redefine_method("to_#{role}!") do
            raise(NoMethodError, "undefined method 'is_" + role.to_s + "?'") unless can_change_role?(role.to_s)
            self.update(role: role.to_s)
            self
          end
        end


      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acts_as_commentable_more-1.2.5 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb
acts_as_commentable_more-1.2.4 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb
acts_as_commentable_more-1.2.3 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb
acts_as_commentable_more-1.2.2 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb
acts_as_commentable_more-1.2.1 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb
acts_as_commentable_more-1.2.0 lib/acts_as_commentable_more/helpers/comment/methods_helper.rb