class ThreeScaleToolbox::Commands::PoliciesCommand::ExportSubcommand

Public Class Methods

command() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 32
def self.command
  Cri::Command.define do
    name        'export'
    usage       'export [opts] <remote> <product>'
    summary     'export product policy chain'
    description 'export product policy chain'

    option      :f, :file, 'Write to file instead of stdout', argument: :required
    option      :o, :output, 'Output format. One of: json|yaml', argument: :required, transform: SerializerTransformer.new
    param       :remote
    param       :service_ref

    runner ExportSubcommand
  end
end

Public Instance Methods

run() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 48
def run
  select_output do |output|
    output.write(serializer.call(product.policies))
  end
end

Private Instance Methods

file() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 75
def file
  options[:file]
end
find_product() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 68
def find_product
  Entities::Service.find(remote: remote,
                         ref: service_ref).tap do |svc|
    raise ThreeScaleToolbox::Error, "Product #{service_ref} does not exist" if svc.nil?
  end
end
product() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 60
def product
  @product ||= find_product
end
remote() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 56
def remote
  @remote ||= threescale_client(arguments[:remote])
end
select_output() { |ios| ... } click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 79
def select_output
  ios = if file
          File.open(file, 'w')
        else
          $stdout
        end
  begin
    yield(ios)
  ensure
    ios.close
  end
end
serializer() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 92
def serializer
  options.fetch(:output, YAMLSerializer.new)
end
service_ref() click to toggle source
# File lib/3scale_toolbox/commands/policies_command/export_command.rb, line 64
def service_ref
  arguments[:service_ref]
end