Sha256: 736c79d846ea21650212b8f78ce7b5089919cd0ea5b242e6b0e1372376ce929a

Contents?: true

Size: 745 Bytes

Versions: 10

Compression:

Stored size: 745 Bytes

Contents

project_name = read_project_name
authorize(project_name, 'admin')
dir = find_project_dir(project_name)
username = ARGV.shift
action = ARGV.shift
unless ['admin','write','read'].member?(action)
  $stderr.puts "Not a valid action (must be one of: read, write, admin)"
  exit 1
end

File.open(File.join(dir, ".lock"), "w+") do |lock|
  lock.flock(File::LOCK_EX)
  begin
    filename = File.join(dir, ".permissions")
    permissions = File.read(filename).split("\n").map { |line| line.strip }.select { |line| line.split('=')[0] != username }
    permissions << "#{username}=#{action}"
    File.open(filename, "w") do |file| 
      permissions.each { |permission| file << permission << "\n" }
    end
  ensure
    lock.flock(File::LOCK_UN)
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hubbard-0.0.9 commands/add-permission.rb
hubbard-0.0.8 commands/add-permission.rb
hubbard-0.0.7 commands/add-permission.rb
hubbard-0.0.6 commands/add-permission.rb
hubbard-0.0.5 commands/add-permission.rb
hubbard-0.0.4 commands/add-permission.rb
hubbard-0.0.3 commands/add-permission.rb
hubbard-0.0.2 commands/add-permission.rb
hubbard-0.0.1 commands/add-permission.rb
hubbard-0.0.0 commands/add-permission.rb