Class: Ironment::CL

Inherits:
Object
  • Object
show all
Defined in:
lib/ironment/cl.rb,
lib/ironment/cl/prompter.rb

Defined Under Namespace

Classes: Prompter

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CL

Returns a new instance of CL.



3
4
5
6
7
8
# File 'lib/ironment/cl.rb', line 3

def initialize(options = {})
  @ironment = options[:ironment] || Ironment.new
  @prompter = options[:prompter] || Prompter.new
  @truster = options[:truster] || Truster.new
  @stderr = options[:stderr] || $stderr
end

Instance Method Details

#exec_with_environment(command, *args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ironment/cl.rb', line 10

def exec_with_environment(command, *args)
  @ironment.exec_with_environment command, *args
rescue Truster::NotTrusted => e
  if @prompter.not_trusted e.runcom
    exec_with_environment command, *args
  end
rescue Truster::Modified => e
  if @prompter.modified e.runcom
    exec_with_environment command, *args
  end
end

#trust(file) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ironment/cl.rb', line 22

def trust(file)
  @truster.trust Runcom.new(file)

  true
rescue Errno::EACCES
  @stderr.puts "ironment: Permission denied"

  false
rescue Errno::ENOENT
  @stderr.puts "ironment: No such file or directory"

  false
rescue Errno::EISDIR
  @stderr.puts "ironment: Is a directory"

  false
end

#untrust(file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ironment/cl.rb', line 40

def untrust(file)
  @truster.untrust Runcom.new(file)

  true
rescue Errno::EACCES
  @stderr.puts "ironment: Permission denied"

  false
rescue Errno::ENOENT
  @stderr.puts "ironment: No such file or directory"

  false
rescue Errno::EISDIR
  @stderr.puts "ironment: Is a directory"

  false
end