class Posgra::CLI::Grant
Constants
- DEFAULT_FILENAME
Public Instance Methods
apply(file)
click to toggle source
# File lib/posgra/cli/grant.rb, line 16 def apply(file) check_fileanem(file) updated = client.apply_grants(file) unless updated Posgra::Logger.instance.info('No change'.intense_blue) end end
export(file = nil)
click to toggle source
# File lib/posgra/cli/grant.rb, line 27 def export(file = nil) check_fileanem(file) dsl = client.export_grants if options[:split] file = DEFAULT_FILENAME unless file log(:info, 'Export Grants') requires = [] dsl.each do |user, content| user = user.gsub(/\s+/, '_') user = '_' if user.empty? grant_file = "#{user}.rb" requires << grant_file log(:info, " write `#{grant_file}`") open(grant_file, 'wb') do |f| f.puts Posgra::CLI::MAGIC_COMMENT f.puts content end end log(:info, " write `#{file}`") open(file, 'wb') do |f| f.puts Posgra::CLI::MAGIC_COMMENT requires.each do |grant_file| f.puts "require '#{File.basename grant_file}'" end end else if file.nil? or file == '-' puts dsl else log(:info, "Export Grants to `#{file}`") open(file, 'wb') do |f| f.puts Posgra::CLI::MAGIC_COMMENT f.puts dsl end end end end