Class: ThreeScaleToolbox::Commands::MethodsCommand::Apply::ApplySubcommand

Inherits:
Cri::CommandRunner
  • Object
show all
Includes:
ThreeScaleToolbox::Command
Defined in:
lib/3scale_toolbox/commands/methods_command/apply_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ThreeScaleToolbox::Command

#config, #config_file, #exit_with_message, #fetch_required_option, included, #keep_alive, #remotes, #threescale_client, #verbose, #verify_ssl

Class Method Details

.commandObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/3scale_toolbox/commands/methods_command/apply_command.rb', line 26

def self.command
  Cri::Command.define do
    name        'apply'
    usage       'apply [opts] <remote> <service> <method>'
    summary     'Update method'
    description 'Update (create if it does not exist) method'

    option      :n, :name, 'Method name', argument: :required
    flag        nil, :disabled, 'Disables this method in all application plans'
    flag        nil, :enabled, 'Enables this method in all application plans'
    option      nil, :description, 'Method description', argument: :required
    ThreeScaleToolbox::CLI.output_flag(self)

    param       :remote
    param       :service_ref
    param       :method_ref

    runner ApplySubcommand
  end
end

Instance Method Details

#runObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/3scale_toolbox/commands/methods_command/apply_command.rb', line 47

def run
  validate_option_params
  hits = service.hits
  method = Entities::Method.find(service: service, ref: method_ref)
  if method.nil?
    method = Entities::Method.create(service: service, attrs: create_method_attrs)
  else
    method.update(method_attrs) unless method_attrs.empty?
  end

  method.disable if option_disabled
  method.enable if option_enabled

  printer.print_record method.attrs
end