Class: Remocon::Command::Create

Inherits:
Object
  • Object
show all
Includes:
InterpreterHelper
Defined in:
lib/remocon/command/create_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

Methods included from InterpreterHelper

#condition_array, #condition_errors, #condition_names, #parameter_errors, #parameter_hash, #read_conditions, #read_parameters

Methods included from ParameterSorter

#sort_parameters

Methods included from Remocon::ConditionSorter

#sort_conditions

Constructor Details

#initialize(opts) ⇒ Create

Returns a new instance of Create.



8
9
10
11
12
13
14
15
16
17
# File 'lib/remocon/command/create_command.rb', line 8

def initialize(opts)
  @opts = opts

  @project_id = ENV.fetch('FIREBASE_PROJECT_ID')
  @conditions_filepath = @opts[:conditions]
  @parameters_filepath = @opts[:parameters]
  @dest_dir = File.join(@opts[:dest], @project_id) if @opts[:dest]

  @cmd_opts = { validate_only: false }
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/remocon/command/create_command.rb', line 19

def run
  validate_options

  artifact = {
    conditions: condition_array,
    parameters: parameter_hash
  }.skip_nil_values.stringify_values

  if @dest_dir
    File.open(File.join(@dest_dir, 'config.json'), 'w+') do |f|
      # remote config allows only string values ;(
      f.write(JSON.pretty_generate(artifact))
      f.flush
    end
  else
    STDOUT.puts JSON.pretty_generate(artifact)
  end

  artifact
end