Class: ThreeScaleToolbox::Commands::PlansCommand::Apply::ApplySubcommand

Inherits:
Cri::CommandRunner
  • Object
show all
Includes:
ThreeScaleToolbox::Command
Defined in:
lib/3scale_toolbox/commands/plans_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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/3scale_toolbox/commands/plans_command/apply_command.rb', line 33

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

    option      :n, :name, 'Plan name', argument: :required
    flag        nil, :default, 'Make default application plan'
    flag        nil, :disabled, 'Disables all methods and metrics in this application plan'
    flag        nil, :enabled, 'Enable application plan'
    flag        :p, :publish, 'Publish application plan'
    flag        nil, :hide, 'Hide application plan'
    option      nil, 'approval-required', 'Applications require approval. true or false', argument: :required, transform: ThreeScaleToolbox::Helper::BooleanTransformer.new
    option      nil, 'cost-per-month', 'Cost per month', argument: :required, transform: method(:Float)
    option      nil, 'setup-fee', 'Setup fee', argument: :required, transform: method(:Float)
    option      nil, 'trial-period-days', 'Trial period days', argument: :required, transform: method(:Integer)
    ThreeScaleToolbox::CLI.output_flag(self)

    param       :remote
    param       :service_ref
    param       :plan_ref

    runner ApplySubcommand
  end
end

Instance Method Details

#runObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/3scale_toolbox/commands/plans_command/apply_command.rb', line 60

def run
  validate_option_params
  plan = Entities::ApplicationPlan.find(service: service, ref: plan_ref)
  if plan.nil?
    plan = Entities::ApplicationPlan.create(service: service,
                                            plan_attrs: create_plan_attrs)
  else
    plan.update(new_plan_attrs) unless new_plan_attrs.empty?
  end

  plan.make_default if option_default
  plan.disable if option_disabled
  plan.enable if option_enabled

  printer.print_record plan.attrs
end