Sha256: 3a8799536e5605f5c17eed62c7a2e7ea5d685fdcf5ef4afaf0b1a1477db91620

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Remocon
  module Command
    class Create
      include Remocon::InterpreterHelper

      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

      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

      private

      def validate_options
        raise ValidationError, 'A condition file must exist' unless File.exist?(@conditions_filepath)
        raise ValidationError, 'A parameter file must exist' unless File.exist?(@parameters_filepath)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remocon-0.1.0 lib/remocon/command/create_command.rb