class ThreeScaleToolbox::Commands::MetricsCommand::Create::CreateSubcommand
Public Class Methods
command()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 22 def self.command Cri::Command.define do name 'create' usage 'create [opts] <remote> <service> <metric-name>' summary 'create metric' description 'Create metric' option :t, 'system-name', 'Metric system name', argument: :required flag nil, :disabled, 'Disables this metric in all application plans' option nil, :unit, 'Metric unit. Default hit', argument: :required option nil, :description, 'Metric description', argument: :required ThreeScaleToolbox::CLI.output_flag(self) param :remote param :service_ref param :metric_name runner CreateSubcommand end end
Public Instance Methods
run()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 43 def run metric = ThreeScaleToolbox::Entities::Metric.create( service: service, attrs: metric_attrs ) metric.disable if option_disabled printer.print_record metric.attrs end
Private Instance Methods
find_service()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 76 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
metric_attrs()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 55 def metric_attrs { 'system_name' => options[:'system-name'], 'unit' => unit, 'friendly_name' => arguments[:metric_name], 'description' => options[:description] }.compact end
option_disabled()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 68 def option_disabled options.fetch(:disabled, false) end
printer()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 91 def printer # keep backwards compatibility options.fetch(:output, CustomPrinter.new(disabled: option_disabled)) end
remote()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 83 def remote @remote ||= threescale_client(arguments[:remote]) end
service()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 72 def service @service ||= find_service end
service_ref()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 87 def service_ref arguments[:service_ref] end
unit()
click to toggle source
# File lib/3scale_toolbox/commands/metrics_command/create_command.rb, line 64 def unit options[:unit] || 'hit' end