Class: Remocon::Config
- Inherits:
-
Object
- Object
- Remocon::Config
- Defined in:
- lib/remocon/command/lib/config.rb
Constant Summary collapse
- REMOCON_PROJECT_ID_KEY =
"REMOCON_FIREBASE_PROJECT_ID"- REMOCON_ACCESS_TOKEN =
"REMOCON_FIREBASE_ACCESS_TOKEN"- REMOCON_PREFIX_KEY =
"REMOCON_PREFIX"- CONFIG_JSON_FILE =
"config.json"- CONDITIONS_FILE_NAME =
"conditions.yml"- PARAMETERS_FILE_NAME =
"parameters.yml"- ETAG_FILE_NAME =
"etag"
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
- #conditions_file_path ⇒ Object
- #config_json_file_path ⇒ Object
- #destination_dir_path ⇒ Object
- #endpoint ⇒ Object
- #etag ⇒ Object
- #etag_file_path ⇒ Object
-
#initialize(opts) ⇒ Config
constructor
A new instance of Config.
- #parameters_file_path ⇒ Object
- #project_dir_path ⇒ Object
- #project_id ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(opts) ⇒ Config
Returns a new instance of Config.
17 18 19 |
# File 'lib/remocon/command/lib/config.rb', line 17 def initialize(opts) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
15 16 17 |
# File 'lib/remocon/command/lib/config.rb', line 15 def opts @opts end |
Instance Method Details
#conditions_file_path ⇒ Object
54 55 56 57 58 |
# File 'lib/remocon/command/lib/config.rb', line 54 def conditions_file_path @conditions_file_path ||= opts[:conditions] || begin File.join(project_dir_path, CONDITIONS_FILE_NAME) end end |
#config_json_file_path ⇒ Object
48 49 50 51 52 |
# File 'lib/remocon/command/lib/config.rb', line 48 def config_json_file_path @config_json_file_path ||= opts[:source] || begin File.join(project_dir_path, CONFIG_JSON_FILE) end end |
#destination_dir_path ⇒ Object
35 36 37 |
# File 'lib/remocon/command/lib/config.rb', line 35 def destination_dir_path @destination_dir_path ||= (opts[:prefix] || opts[:dest] || ENV[REMOCON_PREFIX_KEY]) end |
#endpoint ⇒ Object
21 22 23 |
# File 'lib/remocon/command/lib/config.rb', line 21 def endpoint @endpoint ||= "https://firebaseremoteconfig.googleapis.com/v1/projects/#{project_id}/remoteConfig" end |
#etag ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/remocon/command/lib/config.rb', line 72 def etag @etag ||= begin if opts[:force] && opts[:raw_etag] raise "--force and --raw_etag cannot be specified" end opts[:force] && "*" || opts[:raw_etag] || File.exist?(etag_file_path) && File.open(etag_file_path).read end end |
#etag_file_path ⇒ Object
66 67 68 69 70 |
# File 'lib/remocon/command/lib/config.rb', line 66 def etag_file_path @etag_file_path ||= opts[:etag] || begin File.join(project_dir_path, ETAG_FILE_NAME) end end |
#parameters_file_path ⇒ Object
60 61 62 63 64 |
# File 'lib/remocon/command/lib/config.rb', line 60 def parameters_file_path @parameters_file_path ||= opts[:parameters] || begin File.join(project_dir_path, PARAMETERS_FILE_NAME) end end |
#project_dir_path ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/remocon/command/lib/config.rb', line 39 def project_dir_path @project_dir_path ||= begin dir_path = destination_dir_path (dir_path ? File.join(dir_path, project_id) : project_id).tap do |dir| FileUtils.mkdir_p(dir) end end end |
#project_id ⇒ Object
25 26 27 28 |
# File 'lib/remocon/command/lib/config.rb', line 25 def project_id # FIREBASE_PROJECT_ID is for backward compatibility @project_id ||= (opts[:id] || ENV[REMOCON_PROJECT_ID_KEY] || ENV["FIREBASE_PROJECT_ID"] || raise("--id or #{REMOCON_PROJECT_ID_KEY} env var is required")) end |
#token ⇒ Object
30 31 32 33 |
# File 'lib/remocon/command/lib/config.rb', line 30 def token # REMOTE_CONFIG_ACCESS_TOKEN is for backward compatibility @token ||= (opts[:token] || ENV[REMOCON_ACCESS_TOKEN] || ENV["REMOTE_CONFIG_ACCESS_TOKEN"] || raise("--token or #{REMOCON_ACCESS_TOKEN} env var is required")) end |