class Doorkeeper::Scopes

def [](name)

def [](name)
  select do |scope|
    scope.name.to_sym == name.to_sym
  end.first
end

def add (scope)

def add (scope)
  raise IllegalElement unless valid_element?(scope)
  @scopes << scope
end

def all

def all
  @scopes
end

def default_scope_string

def default_scope_string
  defaults.map(&:name).join(" ")
end

def defaults

def defaults
  select do |scope|
    scope.default
  end
end

def exists? (scope)

def exists? (scope)
  self[scope].present?
end

def initialize

def initialize
  @scopes = []
end

def valid_element?(scope)

def valid_element?(scope)
  REQUIRED_ELEMENT_METHOD.all? do |method|
    scope.respond_to? method
  end
end

def with_names(*names)

def with_names(*names)
  names = names.map(&:to_sym)
  select do |scope|
    names.include? scope.name.to_sym
  end
end