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 collapse
-
#cmd_opts ⇒ Object
readonly
Returns the value of attribute cmd_opts.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Pull
constructor
A new instance of Pull.
- #require_conditions_file_path ⇒ Object
- #require_parameters_file_path ⇒ Object
- #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.
10 11 12 13 |
# File 'lib/remocon/command/pull_command.rb', line 10 def initialize(opts) @config = Remocon::Config.new(opts) @cmd_opts = { validate_only: false } end |
Instance Attribute Details
#cmd_opts ⇒ Object (readonly)
Returns the value of attribute cmd_opts.
8 9 10 |
# File 'lib/remocon/command/pull_command.rb', line 8 def cmd_opts @cmd_opts end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/remocon/command/pull_command.rb', line 8 def config @config end |
Instance Method Details
#require_conditions_file_path ⇒ Object
19 20 21 |
# File 'lib/remocon/command/pull_command.rb', line 19 def require_conditions_file_path config.conditions_file_path end |
#require_parameters_file_path ⇒ Object
15 16 17 |
# File 'lib/remocon/command/pull_command.rb', line 15 def require_parameters_file_path config.parameters_file_path end |
#run ⇒ Object
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 52 |
# File 'lib/remocon/command/pull_command.rb', line 23 def run raw_json, etag = do_request raw_hash = JSON.parse(raw_json).with_indifferent_access raise "etag cannot be fetched. please try again" unless etag conditions = raw_hash[:conditions] || [] parameters = raw_hash[:parameters] || {} File.open(config.conditions_file_path, "w+") do |f| f.write(JSON.parse(Remocon::ConditionFileDumper.new(sort_conditions(conditions)).dump.to_json).to_yaml) f.flush end File.open(config.parameters_file_path, "w+") do |f| f.write(JSON.parse(Remocon::ParameterFileDumper.new(sort_parameters(parameters)).dump.to_json).to_yaml) f.flush end File.open(config.config_json_file_path, "w+") do |f| f.write(JSON.pretty_generate({ conditions: sort_conditions(conditions), parameters: sort_parameters(parameters) })) f.flush end File.open(config.etag_file_path, "w+") do |f| f.write(etag) f.flush end end |