Class: Remocon::Command::Pull
- Inherits:
-
Object
- Object
- Remocon::Command::Pull
- Includes:
- InterpreterHelper
- Defined in:
- lib/remocon/command/pull_command.rb
Constant Summary
Constants included from ParameterSorter
ParameterSorter::PARAMETER_KEYS
Constants included from Remocon::ConditionSorter
Remocon::ConditionSorter::CONDITION_KEYS
Instance Attribute Summary
Attributes included from InterpreterHelper
#cmd_opts, #conditions_filepath, #parameters_filepath
Instance Method Summary collapse
-
#initialize(opts) ⇒ Pull
constructor
A new instance of Pull.
- #run ⇒ Object
Methods included from InterpreterHelper
#condition_array, #condition_errors, #condition_names, #parameter_errors, #parameter_hash, #read_conditions, #read_parameters
Methods included from ParameterSorter
Methods included from Remocon::ConditionSorter
Constructor Details
#initialize(opts) ⇒ Pull
Returns a new instance of Pull.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/remocon/command/pull_command.rb', line 8 def initialize(opts) @opts = opts @project_id = ENV.fetch('FIREBASE_PROJECT_ID') @token = ENV.fetch('REMOTE_CONFIG_ACCESS_TOKEN') @url = "https://firebaseremoteconfig.googleapis.com/v1/projects/#{@project_id}/remoteConfig" @dest_dir = File.join(@opts[:dest], @project_id) if @opts[:dest] @cmd_opts = { validate_only: false } end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/remocon/command/pull_command.rb', line 19 def run if @dest_dir FileUtils.mkdir_p(@dest_dir) raw_hash = JSON.parse(raw_json).with_indifferent_access raise 'etag cannot be fetched. please try again' unless @etag conditions, parameters = [raw_hash[:conditions] || [], raw_hash[:parameters] || {}] File.open(File.join(@dest_dir, "conditions.yml"), 'w+') do |f| f.write(JSON.parse(Remocon::ConditionFileDumper.new(sort_conditions(conditions)).dump.to_json).to_yaml) f.flush end File.open(File.join(@dest_dir, "parameters.yml"), 'w+') do |f| f.write(JSON.parse(Remocon::ParameterFileDumper.new(sort_parameters(parameters)).dump.to_json).to_yaml) f.flush end File.open(File.join(@dest_dir, "config.json"), 'w+') do |f| f.write(JSON.pretty_generate({ conditions: sort_conditions(conditions), parameters: sort_parameters(parameters) })) f.flush end File.open(File.join(@dest_dir, 'etag'), 'w+') do |f| f.write(@etag) f.flush end else STDOUT.puts raw_json end end |