Class: Warden::GitHub::Rails::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/warden/github/rails/config.rb

Constant Summary collapse

BadConfig =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
21
22
# File 'lib/warden/github/rails/config.rb', line 18

def initialize
  @default_scope = :user
  @scopes = {}
  @teams = {}
end

Instance Attribute Details

#default_scopeObject

Default scope to use when not explicitly specified.



8
9
10
# File 'lib/warden/github/rails/config.rb', line 8

def default_scope
  @default_scope
end

#scopesObject (readonly)

The list of scopes and their configs. This is used to add custom configs to a specific scope. When using a scope that is not listed here, it will use the default configs from warden-github.



13
14
15
# File 'lib/warden/github/rails/config.rb', line 13

def scopes
  @scopes
end

#teamsObject (readonly)

A hash containing team alias names and their numeric id.



16
17
18
# File 'lib/warden/github/rails/config.rb', line 16

def teams
  @teams
end

Instance Method Details

#add_scope(name, config = {}) ⇒ Object

Adds a scope with custom configurations to the list of scopes.



25
26
27
# File 'lib/warden/github/rails/config.rb', line 25

def add_scope(name, config={})
  scopes[name] = config
end

#add_team(name, id) ⇒ Object

Maps a team id to a name in order to easier reference it.



30
31
32
# File 'lib/warden/github/rails/config.rb', line 30

def add_team(name, id)
  teams[name.to_sym] = Integer(id)
end

#team_id(team) ⇒ Object

Gets the team id for a team id or alias.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/warden/github/rails/config.rb', line 35

def team_id(team)
  # In ruby 1.8 doing a Integer(:symbol) returns an integer. Thus, test
  # for symbol first.
  if team.is_a? Symbol
    teams.fetch(team)
  else
    Integer(team)  rescue teams.fetch(team.to_sym)
  end
rescue IndexError
  fail BadConfig, "No team id defined for team #{team}."
end