Class: Remocon::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#optsObject (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_pathObject



58
59
60
61
62
# File 'lib/remocon/command/lib/config.rb', line 58

def conditions_file_path
  @conditions_file_path ||= opts[:conditions] || begin
    File.join(project_dir_path, CONDITIONS_FILE_NAME)
  end
end

#config_json_file_pathObject



52
53
54
55
56
# File 'lib/remocon/command/lib/config.rb', line 52

def config_json_file_path
  @config_json_file_path ||= opts[:source] || begin
    File.join(project_dir_path, CONFIG_JSON_FILE)
  end
end

#destination_dir_pathObject



39
40
41
# File 'lib/remocon/command/lib/config.rb', line 39

def destination_dir_path
  @destination_dir_path ||= (opts[:prefix] || opts[:dest] || ENV[REMOCON_PREFIX_KEY])
end

#endpointObject



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

#etagObject



76
77
78
79
80
81
82
83
84
# File 'lib/remocon/command/lib/config.rb', line 76

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.try(:strip)
end

#etag_file_pathObject



70
71
72
73
74
# File 'lib/remocon/command/lib/config.rb', line 70

def etag_file_path
  @etag_file_path ||= opts[:etag] || begin
    File.join(project_dir_path, ETAG_FILE_NAME)
  end
end

#merge?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/remocon/command/lib/config.rb', line 86

def merge?
  @merge ||= opts[:merge]
end

#parameters_file_pathObject



64
65
66
67
68
# File 'lib/remocon/command/lib/config.rb', line 64

def parameters_file_path
  @parameters_file_path ||= opts[:parameters] || begin
    File.join(project_dir_path, PARAMETERS_FILE_NAME)
  end
end

#project_dir_pathObject



43
44
45
46
47
48
49
50
# File 'lib/remocon/command/lib/config.rb', line 43

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_idObject



29
30
31
32
# File 'lib/remocon/command/lib/config.rb', line 29

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

#service_json_file_pathObject



25
26
27
# File 'lib/remocon/command/lib/config.rb', line 25

def service_json_file_path
  @service_json_file_path ||= opts[:"service-json"]
end

#tokenObject



34
35
36
37
# File 'lib/remocon/command/lib/config.rb', line 34

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