class ThreeScaleToolbox::Commands::PlansCommand::Create::CreateSubcommand
Public Class Methods
command()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 23 def self.command Cri::Command.define do name 'create' usage 'create [opts] <remote> <service> <plan-name>' summary 'create application plan' description 'Create application plan' option :t, 'system-name', 'Application plan system name', argument: :required flag nil, :default, 'Make default application plan' flag nil, :disabled, 'Disables all methods and metrics in this application plan' flag :p, :publish, 'Publish 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_name runner CreateSubcommand end end
Public Instance Methods
run()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 48 def run plan = create_application_plan plan.make_default if option_default plan.disable if option_disabled printer.print_record plan.attrs end
Private Instance Methods
create_application_plan()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 57 def create_application_plan ThreeScaleToolbox::Entities::ApplicationPlan.create( service: service, plan_attrs: plan_attrs ) end
find_service()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 97 def find_service Entities::Service.find(remote: remote, ref: service_ref).tap do |svc| raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil? end end
option_default()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 81 def option_default options.fetch(:default, false) end
option_disabled()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 85 def option_disabled options.fetch(:disabled, false) end
option_publish()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 89 def option_publish options.fetch(:publish, false) end
plan_attrs()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 64 def plan_attrs plan_basic_attrs.tap do |params| params['state'] = 'published' if option_publish end end
plan_basic_attrs()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 70 def plan_basic_attrs { 'name' => arguments[:plan_name], 'system_name' => options[:'system-name'], 'approval_required' => options[:'approval-required'], 'cost_per_month' => options[:'cost-per-month'], 'setup_fee' => options[:'setup-fee'], 'trial_period_days' => options[:'trial-period-days'] }.compact end
printer()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 112 def printer # keep backwards compatibility options.fetch(:output, CustomPrinter.new(option_default, option_disabled)) end
remote()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 104 def remote @remote ||= threescale_client(arguments[:remote]) end
service()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 93 def service @service ||= find_service end
service_ref()
click to toggle source
# File lib/3scale_toolbox/commands/plans_command/create_command.rb, line 108 def service_ref arguments[:service_ref] end