Class: Gratan::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gratan/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



2
3
4
5
6
7
# File 'lib/gratan/client.rb', line 2

def initialize(options = {})
  @options = options
  @options[:identifier] ||= Gratan::Identifier::Null.new
  client = Mysql2::Client.new(options)
  @driver = Gratan::Driver.new(client, options)
end

Instance Method Details

#apply(file, options = {}) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/gratan/client.rb', line 30

def apply(file, options = {})
  options = @options.merge(options)

  in_progress do
    walk(file, options)
  end
end

#export(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gratan/client.rb', line 9

def export(options = {})
  options = @options.merge(options)
  exported = Gratan::Exporter.export(@driver, options)

  if block_given?
    exported.sort_by {|user_host, attrs|
      user_host
    }.chunk {|user_host, attrs|
      user_host[0].empty? ? 'root' : user_host[0]
    }.each {|user, grants|
      h = {}
      grants.each {|k, v| h[k] = v }
      dsl = Gratan::DSL.convert(h, options)
      yield(user, dsl)
    }
  else
    exported = Gratan::Exporter.export(@driver, options)
    Gratan::DSL.convert(exported, options)
  end
end