Sha256: abf6e057a720217a9fe59e7056bba1a949c0543d7115bfa9503c42aaa0baa04d

Contents?: true

Size: 1.65 KB

Versions: 21

Compression:

Stored size: 1.65 KB

Contents

module ThreeScaleToolbox
  module Commands
    module MetricsCommand
      module Delete
        class DeleteSubcommand < Cri::CommandRunner
          include ThreeScaleToolbox::Command

          def self.command
            Cri::Command.define do
              name        'delete'
              usage       'delete [opts] <remote> <service> <metric>'
              summary     'delete metric'
              description 'Delete metric'

              param       :remote
              param       :service_ref
              param       :metric_ref

              runner DeleteSubcommand
            end
          end

          def run
            metric.delete
            puts "Metric id: #{metric.id} deleted"
          end

          private

          def service
            @service ||= find_service
          end

          def metric
            @metric ||= find_metric
          end

          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

          def find_metric
            Entities::Metric.find(service: service, ref: metric_ref).tap do |p|
              raise ThreeScaleToolbox::Error, "Metric #{metric_ref} does not exist" if p.nil?
            end
          end

          def remote
            @remote ||= threescale_client(arguments[:remote])
          end

          def service_ref
            arguments[:service_ref]
          end

          def metric_ref
            arguments[:metric_ref]
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/commands/metrics_command/delete_command.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/commands/metrics_command/delete_command.rb