Module: Passport::Settings::ClassMethods
- Defined in:
- lib/passport/core/settings.rb
Constant Summary collapse
- KEY =
"services"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#config ⇒ Object
Returns the value of attribute config.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #configure(value) ⇒ Object
- #consumer(key) ⇒ Object
- #credentials(service) ⇒ Object
- #include?(service) ⇒ Boolean
- #key(path) ⇒ Object
- #service_names ⇒ Object
- #services ⇒ Object
- #token(key, throw_error = true) ⇒ Object
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
12 13 14 |
# File 'lib/passport/core/settings.rb', line 12 def adapter @adapter end |
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/passport/core/settings.rb', line 12 def config @config end |
#root ⇒ Object
Returns the value of attribute root.
12 13 14 |
# File 'lib/passport/core/settings.rb', line 12 def root @root end |
Instance Method Details
#configure(value) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/passport/core/settings.rb', line 14 def configure(value) self.config = (value.is_a?(String) ? YAML.load_file(value) : value).recursively_symbolize_keys! if self.config.has_key?(:connect) self.config[:services] = self.config.delete(:connect) puts "[Deprecation] change 'connect' to 'services' in Passport configuration" end self.config[:adapter] ||= "object" self.adapter = config[:adapter] install self.config end |
#consumer(key) ⇒ Object
70 71 72 |
# File 'lib/passport/core/settings.rb', line 70 def consumer(key) token(key).consumer end |
#credentials(service) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/passport/core/settings.rb', line 42 def credentials(service) result = key("#{KEY}.#{service.to_s}") unless result && result.has_key?(:key) && result.has_key?(:secret) raise SettingsError.new("Please specify both a key and secret for ':#{service}'") end result end |
#include?(service) ⇒ Boolean
58 59 60 |
# File 'lib/passport/core/settings.rb', line 58 def include?(service) !credentials(service).nil? end |
#key(path) ⇒ Object
36 37 38 39 40 |
# File 'lib/passport/core/settings.rb', line 36 def key(path) result = self.config path.to_s.split(".").each { |node| result = result[node.to_sym] if result } result end |
#service_names ⇒ Object
54 55 56 |
# File 'lib/passport/core/settings.rb', line 54 def service_names services.keys.collect(&:to_s) end |
#services ⇒ Object
50 51 52 |
# File 'lib/passport/core/settings.rb', line 50 def services key(KEY) end |
#token(key, throw_error = true) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/passport/core/settings.rb', line 62 def token(key, throw_error = true) unless Passport.include?(key) and !key.to_s.empty? raise SettingsError.new("can't find key '#{key.to_s}' in Passport.config" ) if throw_error else "#{key.to_s.camelcase}Token".constantize end end |