Class: ChangePerms

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-chmod/perms.rb

Instance Method Summary collapse

Constructor Details

#initialize(perms, type, file) ⇒ ChangePerms



5
6
7
8
9
# File 'lib/simple-chmod/perms.rb', line 5

def initialize(perms,type,file)
  @perms = perms
  @type = type
  @file = file
end

Instance Method Details

#resultObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple-chmod/perms.rb', line 11

def result
  if @perms == 'none'
    shell_script_output = `chmod #{@type}-rwx #{@file}`
    print "Changed permissions.\n"
  elsif @perms == 'read write' || @perms == 'read xcute' || @perms == 'write read' || @perms == 'write xcute' || @perms == 'xcute read' || @perms == 'xcute write' || @perms == 'read' || @perms == 'write' || @perms == 'xcute' ||@perms == 'read write xcute'
    replaceperms = @perms.gsub("read", "r").gsub("write", "w").gsub("xcute", "x")
    finalperms = replaceperms.delete("\s")
    shell_script_output = `chmod #{@type}-rwx #{@file}`
    shell_script_output = `chmod #{@type}+#{finalperms} #{@file}`
    print "Changed permissions.\n"
  else
    print "No valid file permissions.\n"
  end
end