Class: Firebase::Admin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase/admin/config.rb

Overview

Configuration options used to initialize an App.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = 
end

Instance Attribute Details

#project_idObject (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_idObject (readonly)

Returns the value of attribute service_account_id.



10
11
12
# File 'lib/firebase/admin/config.rb', line 10

def 
  @service_account_id
end

Class Method Details

.from_envFirebase::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.

Parameters:

  • file (File, String)

    The path of the configuration file.

Returns:



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.

Parameters:

  • json (String)

    A configuration encoded as a JSON string.

Returns:



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