Sha256: c8b9c65993d3b1889f2b5549d3a5bfca0a3c26b32530cd06fc65d80b01ce7e7b

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

module Warden
  module GitHub
    module Rails
      class Config
        BadConfig = Class.new(StandardError)

        # Default scope to use when not explicitly specified.
        attr_accessor :default_scope

        # 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.
        attr_reader :scopes

        # A hash containing team alias names and their numeric id.
        attr_reader :teams

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

        # Adds a scope with custom configurations to the list of scopes.
        def add_scope(name, config={})
          scopes[name] = config
        end

        # Maps a team id to a name in order to easier reference it.
        def add_team(name, id)
          teams[name.to_sym] = Integer(id)
        end

        # Gets the team id for a team id or alias.
        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
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
warden-github-rails-1.3.0 lib/warden/github/rails/config.rb
warden-github-rails-1.2.3 lib/warden/github/rails/config.rb
warden-github-rails-1.2.2 lib/warden/github/rails/config.rb
warden-github-rails-1.2.1 lib/warden/github/rails/config.rb
warden-github-rails-1.2.0 lib/warden/github/rails/config.rb
warden-github-rails-1.1.2 lib/warden/github/rails/config.rb
warden-github-rails-1.1.1 lib/warden/github/rails/config.rb
warden-github-rails-1.1.0 lib/warden/github/rails/config.rb
warden-github-rails-thinknear-fork-1.1.0 lib/warden/github/rails/config.rb
warden-github-rails-1.0.1 lib/warden/github/rails/config.rb
warden-github-rails-1.0.0 lib/warden/github/rails/config.rb