Sha256: 89aaae829e8f91c2e4c7afb8f44c8ebd3a2d50b31320f7d1613f1a89b2d9d955
Contents?: true
Size: 1.08 KB
Versions: 5
Compression:
Stored size: 1.08 KB
Contents
module Doorkeeper class Scopes include Enumerable REQUIRED_ELEMENT_METHOD = [:name, :default] class IllegalElement < StandardError; end delegate :each, :to => :@scopes def initialize @scopes = [] end def [](name) select do |scope| scope.name.to_sym == name.to_sym end.first end def exists? (scope) self[scope].present? end def all_included?(scopes_string) scopes_string.split(" ").all? { |s| self.exists?(s) } end def add (scope) raise IllegalElement unless valid_element?(scope) @scopes << scope end def all @scopes end def defaults select do |scope| scope.default end end def default_scope_string defaults.map(&:name).join(" ") end def with_names(*names) names = names.map(&:to_sym) select do |scope| names.include? scope.name.to_sym end end private def valid_element?(scope) REQUIRED_ELEMENT_METHOD.all? do |method| scope.respond_to? method end end end end
Version data entries
5 entries across 5 versions & 1 rubygems