Class: SlackRubyBotAuthorization::Role
Overview
Maps roles to users and commands.
Constant Summary
Constants included
from Utils
Utils::EmptyDenialProc
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#extract_command, #extract_details, #extract_user, #normalize_string
Constructor Details
#initialize(name, &blk) ⇒ Role
Returns a new instance of Role.
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 77
def initialize(name, &blk)
@name = normalize_string(name)
@users = Set.new
@commands = Set.new
return unless block_given?
blk.arity == 1 ? yield(self) : instance_eval(&blk)
end
|
Instance Attribute Details
#denial_handler ⇒ Object
Returns the value of attribute denial_handler.
75
76
77
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 75
def denial_handler
@denial_handler
end
|
#name ⇒ Object
Returns the value of attribute name.
75
76
77
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 75
def name
@name
end
|
Instance Method Details
#add_commands(*commands) ⇒ Object
93
94
95
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 93
def add_commands(*commands)
commands.each { |command| @commands << command }
end
|
#add_denial_handler(aproc) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 97
def add_denial_handler(aproc)
unless aproc.arity == 3
raise(DenialProcArityException, 'Must accept 3 arguments')
end
@denial_handler = aproc
end
|
#add_users(*users) ⇒ Object
89
90
91
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 89
def add_users(*users)
users.each { |user| @users << normalize_string(user) }
end
|
#command?(command) ⇒ Boolean
131
132
133
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 131
def command?(command)
@commands.include?(command)
end
|
#command_names ⇒ Object
143
144
145
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 143
def command_names
commands.map(&:name).sort
end
|
#commands ⇒ Object
139
140
141
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 139
def commands
@commands.to_a
end
|
#enable_slack_builtin_commands(*commands) ⇒ Object
105
106
107
108
109
110
111
112
113
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 105
def enable_slack_builtin_commands(*commands)
commands = BUILTIN_COMMANDS if commands.empty?
commands.each do |command|
raise(UnknownBuiltinCommandException, "Unknown command '#{command}'") \
unless BUILTIN_COMMANDS.include?(command.downcase)
add_commands(command)
end
end
|
#remove_commands(*commands) ⇒ Object
119
120
121
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 119
def remove_commands(*commands)
commands.each { |command| @commands.delete(command) }
end
|
#remove_denial_handler ⇒ Object
123
124
125
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 123
def remove_denial_handler
@denial_handler = Utils::EmptyDenialProc
end
|
#remove_users(*users) ⇒ Object
115
116
117
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 115
def remove_users(*users)
users.each { |user| @users.delete(normalize_string(user)) }
end
|
#user?(user) ⇒ Boolean
127
128
129
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 127
def user?(user)
@users.include?(normalize_string(user))
end
|
#users ⇒ Object
135
136
137
|
# File 'lib/slack_ruby_bot_authorization/role.rb', line 135
def users
@users.to_a.sort
end
|