class Mysqlman::Role

Attributes

name[R]

Public Class Methods

all() click to toggle source
# File lib/mysqlman/role.rb, line 6
def all
  files = Dir.glob("#{ROLE_DIR}/*.yml")
  files.map do |file|
    YAML.load_file(file).map do |name, config|
      new(name, config)
    end
  end.flatten
end
find(name) click to toggle source
# File lib/mysqlman/role.rb, line 15
def find(name)
  roles = all
  roles.select { |role| role.name == name }.first
end
new(name, config) click to toggle source
# File lib/mysqlman/role.rb, line 23
def initialize(name, config)
  @name = name
  @config = config
end

Public Instance Methods

all_priv?(privs) click to toggle source
# File lib/mysqlman/role.rb, line 70
def all_priv?(privs)
  privs.map(&:upcase).include?('ALL')
end
global_privs() click to toggle source
# File lib/mysqlman/role.rb, line 32
def global_privs
  return if @config['global'].nil?
  parse_privs(@config['global'])
end
grantable?(privs) click to toggle source
# File lib/mysqlman/role.rb, line 64
def grantable?(privs)
  privs.map(&:upcase).any? do |priv|
    priv.tr('_', ' ') == 'GRANT OPTION'
  end
end
parse_privs(privs, schema = nil, table = nil) click to toggle source
# File lib/mysqlman/role.rb, line 53
def parse_privs(privs, schema = nil, table = nil)
  return Privs.all(schema, table, grantable?(privs)) if all_priv?(privs)
  privs.map do |priv|
    {
      schema: schema,
      table: table,
      type: priv.upcase.tr('_', ' ')
    }
  end
end
privs() click to toggle source
# File lib/mysqlman/role.rb, line 28
def privs
  [global_privs, schema_privs, table_privs].compact.flatten
end
schema_privs() click to toggle source
# File lib/mysqlman/role.rb, line 37
def schema_privs
  return if @config['schema'].nil?
  @config['schema'].map do |schema_name, privs|
    parse_privs(privs, schema_name)
  end
end
table_privs() click to toggle source
# File lib/mysqlman/role.rb, line 44
def table_privs
  return if @config['table'].nil?
  @config['table'].map do |schema_name, table_config|
    table_config.map do |table_name, privs|
      parse_privs(privs, schema_name, table_name)
    end
  end
end