Module: Monk::Id
- Defined in:
- lib/monk/id.rb,
lib/monk/id/version.rb
Overview
Integrate Monk ID on the server-side by accessing payloads from the client-side JavaScript.
Constant Summary
- CONFIG_FILE =
Expected path of config file in Rails and Sinatra relative to the app's root directory.
'config/monk_id.yml'.freeze
- COOKIE_NAME =
Name of the cookie that (optionally) stores the payload.
'_monkIdPayload'.freeze
- VERSION =
Current version of the library.
'1.2.0'.freeze
Class Method Summary collapse
-
.config(key) ⇒ *
Get a config value.
-
.load_config(path = nil, environment = nil) ⇒ Hash<String>
Load a YAML config file for a specific environment.
-
.load_payload(encoded_payload = nil) ⇒ Hash<Symbol>
Load a payload from the client-side.
-
.logged_in? ⇒ Boolean
(also: signed_in?)
Check whether there's a logged in user.
-
.user_email ⇒ String?
Get the logged in user's email address.
-
.user_id ⇒ String?
Get the logged in user's UUID.
Class Method Details
.config(key) ⇒ *
Get a config value. Attempts to load the config if it hasn't already been loaded.
52 53 54 55 56 |
# File 'lib/monk/id.rb', line 52 def config(key) load_config unless @config @config[key] end |
.load_config(path = nil, environment = nil) ⇒ Hash<String>
Load a YAML config file for a specific environment. Rails and Sinatra apps don't need to call this method if the config file is stored at CONFIG_FILE, as it's loaded automatically.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/monk/id.rb', line 35 def load_config(path = nil, environment = nil) path ||= config_path_from_environment environment ||= config_environment config = YAML.load_file(path)[environment] valid_config?(config) @config = config end |
.load_payload(encoded_payload = nil) ⇒ Hash<Symbol>
Load a payload from the client-side.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/monk/id.rb', line 64 def load_payload(encoded_payload = nil) payload = select_payload(encoded_payload) return @payload = {} unless payload begin payload = decode_payload(payload) valid = valid_payload?(payload) rescue valid = false end @payload = valid ? payload : {} end |
.logged_in? ⇒ Boolean Also known as: signed_in?
Check whether there's a logged in user.
98 99 100 |
# File 'lib/monk/id.rb', line 98 def logged_in? !user_id.nil? end |
.user_email ⇒ String?
Get the logged in user's email address.
91 92 93 |
# File 'lib/monk/id.rb', line 91 def user_email payload_user(:email) end |
.user_id ⇒ String?
Get the logged in user's UUID.
83 84 85 |
# File 'lib/monk/id.rb', line 83 def user_id payload_user(:id) end |