Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Further limit usage of Lita.config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Feb 8, 2014
1 parent f1b922e commit 9b9923a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/lita.rb
Expand Up @@ -65,6 +65,12 @@ def configure
yield config
end

def configure_robot
new_config = Config.default_config
yield config
robots << Robot.new(new_config)
end

# Clears the global configuration object. The next call to {Lita.config}
# will create a fresh config object.
# @return [void]
Expand Down Expand Up @@ -96,7 +102,7 @@ def run(config_path = nil)
if robots.empty?
Robot.new(default_robot_config).run
else
robots.each { robot.run }
robots.each { |robot| robot.run }
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/lita/authorization.rb
Expand Up @@ -39,8 +39,14 @@ def user_in_group?(user, group)
# Checks if a user is an administrator.
# @param user [Lita::User] The user.
# @return [Boolean] Whether or not the user is an administrator.
def user_is_admin?(user)
Array(Lita.config.robot.admins).include?(user.id)
def user_is_admin?(user, robot = nil)
config = if robot
robot.config
else
Lita.config
end

Array(config.robot.admins).include?(user.id)
end

# Returns a list of all authorization groups.
Expand Down
2 changes: 1 addition & 1 deletion lib/lita/config.rb
Expand Up @@ -35,7 +35,7 @@ def load_user_config(config_path = nil)

private

# Adds and populates a Config object to Lita.config.handlers for every
# Adds and populates a Config object to config.handlers for every
# registered handler that implements self.default_config.
def load_handler_configs(config)
Lita.handlers.each do |handler|
Expand Down
2 changes: 1 addition & 1 deletion spec/lita/adapters/shell_spec.rb
Expand Up @@ -5,7 +5,7 @@
name: "Lita",
mention_name: "LitaBot",
alias: "/",
config: Lita.config
config: Lita::Config.default_config
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lita/robot_spec.rb
@@ -1,7 +1,7 @@
require "spec_helper"

describe Lita::Robot do
subject { described_class.new(Lita.config) }
subject { described_class.new(Lita::Config.default_config) }

it "logs and quits if the specified adapter can't be found" do
adapter_registry = double("adapter_registry")
Expand Down

0 comments on commit 9b9923a

Please sign in to comment.