Class: Gratan::Client
- Inherits:
-
Object
- Object
- Gratan::Client
- Includes:
- Logger::Helper
- Defined in:
- lib/gratan/client.rb
Instance Method Summary collapse
- #apply(file, options = {}) ⇒ Object
- #chunk_by_user(exported) ⇒ Object
- #export(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Logger::Helper
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 |
# File 'lib/gratan/client.rb', line 4 def initialize( = {}) = [:identifier] ||= Gratan::Identifier::Null.new client = Mysql2::Client.new() @driver = Gratan::Driver.new(client, ) end |
Instance Method Details
#apply(file, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/gratan/client.rb', line 58 def apply(file, = {}) = .merge() in_progress do walk(file, ) end end |
#chunk_by_user(exported) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gratan/client.rb', line 35 def chunk_by_user(exported) chunked = {} exported.sort_by {|user_host, attrs| user_host[0] }.chunk {|user_host, attrs| user_host[0] }.each {|user, grants| merged_attrs = {} hosts = [] grants.each do |user_host, attrs| hosts << user_host[1] merged_attrs.deep_merge!(attrs) end user_host = [user, hosts.sort] chunked[user_host] = merged_attrs } chunked end |
#export(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gratan/client.rb', line 11 def export( = {}) = .merge() exported = Gratan::Exporter.export(@driver, ) if [:chunk_by_user] exported = chunk_by_user(exported) end if block_given? exported.sort_by {|user_host, attrs| user_host[0].empty? ? 'root' : user_host[0] }.chunk {|user_host, attrs| user_host[0].empty? ? 'root' : user_host[0] }.each {|user, grants| h = {} grants.sort_by {|k, v| k }.each {|k, v| h[k] = v } dsl = Gratan::DSL.convert(h, ) yield(user, dsl) } else Gratan::DSL.convert(exported, ) end end |