Class: Firebase::Admin::Config
- Inherits:
-
Object
- Object
- Firebase::Admin::Config
- Defined in:
- lib/firebase/admin/config.rb
Overview
Configuration options used to initialize an App.
Instance Attribute Summary collapse
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#service_account_id ⇒ Object
readonly
Returns the value of attribute service_account_id.
Class Method Summary collapse
-
.from_env ⇒ Firebase::Admin::Config
Loads a configuration using the FIREBASE_CONFIG environment variable.
-
.from_file(file) ⇒ Firebase::Admin::Config
Loads a configuration from a file.
-
.from_json(json) ⇒ Firebase::Admin::Config
Loads a configuration from JSON.
Instance Method Summary collapse
-
#initialize(project_id: nil, service_account_id: nil) ⇒ Config
constructor
Initializes the configuration object.
Constructor Details
#initialize(project_id: nil, service_account_id: nil) ⇒ Config
Initializes the configuration object.
53 54 55 56 |
# File 'lib/firebase/admin/config.rb', line 53 def initialize(project_id: nil, service_account_id: nil) @project_id = project_id @service_account_id = service_account_id end |
Instance Attribute Details
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
10 11 12 |
# File 'lib/firebase/admin/config.rb', line 10 def project_id @project_id end |
#service_account_id ⇒ Object (readonly)
Returns the value of attribute service_account_id.
10 11 12 |
# File 'lib/firebase/admin/config.rb', line 10 def service_account_id @service_account_id end |
Class Method Details
.from_env ⇒ Firebase::Admin::Config
Loads a configuration using the FIREBASE_CONFIG environment variable.
If the value of the FIREBASE_CONFIG environment variable starts with “{” it is parsed as a JSON object, otherwise it is interpreted as a path to the config file.
19 20 21 22 23 24 |
# File 'lib/firebase/admin/config.rb', line 19 def from_env config = ENV[FIREBASE_CONFIG_ENV_VAR] return new if config.nil? return from_json(config) if config.start_with?("{") from_file(config) end |
.from_file(file) ⇒ Firebase::Admin::Config
Loads a configuration from a file.
32 33 34 35 |
# File 'lib/firebase/admin/config.rb', line 32 def from_file(file) json = file.is_a?(File) ? file.read : File.read(file) from_json(json) end |
.from_json(json) ⇒ Firebase::Admin::Config
Loads a configuration from JSON.
43 44 45 46 47 48 49 |
# File 'lib/firebase/admin/config.rb', line 43 def from_json(json) data = JSON.parse(json) new( project_id: data["projectId"], service_account_id: data["serviceAccountId"] ) end |