Sha256: 9d13a6aff1109c913e2badd3d7cf3ac4fb9d1b51553974ee66e6eae746549708

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

class Gratan::Exporter
  def self.export(driver, options = {}, &block)
    self.new(driver, options).export(&block)
  end

  def initialize(driver, options = {})
    @driver = driver
    @options = options
  end

  def export
    grants = []

    @driver.each_user do |user, host|
      next if user =~ @options[:ignore_user]

      if @options[:target_user]
        next unless user =~ @options[:target_user]
      end

      @driver.show_grants(user, host) do |stmt|
        grants << Gratan::GrantParser.parse(stmt)
      end
    end

    pack(grants)
  end

  private

  def pack(grants)
    packed = {}

    grants.each do |grant|
      user = grant.delete(:user)
      host = grant.delete(:host)
      user_host = [user, host]
      object = grant.delete(:object)
      next if object =~ @options[:ignore_object]
      identified = grant.delete(:identified)
      required = grant.delete(:require)

      packed[user_host] ||= {:objects => {}, :options => {}}
      packed[user_host][:objects][object] = grant
      packed[user_host][:options][:required] = required if required

      if @options[:with_identifier] and identified
        packed[user_host][:options][:identified] = identified
      end
    end

    packed
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gratan-0.3.1.beta2 lib/gratan/exporter.rb
gratan-0.3.1.beta lib/gratan/exporter.rb
gratan-0.3.0 lib/gratan/exporter.rb
gratan-0.3.0.beta lib/gratan/exporter.rb
gratan-0.2.9 lib/gratan/exporter.rb
gratan-0.2.9.beta3 lib/gratan/exporter.rb
gratan-0.2.9.beta2 lib/gratan/exporter.rb
gratan-0.2.9.beta lib/gratan/exporter.rb
gratan-0.2.8 lib/gratan/exporter.rb
gratan-0.2.8.beta3 lib/gratan/exporter.rb
gratan-0.2.8.beta2 lib/gratan/exporter.rb
gratan-0.2.8.beta lib/gratan/exporter.rb
gratan-0.2.7 lib/gratan/exporter.rb