Class: Ironment::CL

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

Defined Under Namespace

Classes: Prompter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CL

Returns a new instance of CL.



25
26
27
28
29
# File 'lib/ironment/cl.rb', line 25

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

Class Method Details

.rescue_common_exceptions(method_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ironment/cl.rb', line 4

def rescue_common_exceptions(method_name)
  new_name = "original_#{method_name}"

  alias_method new_name, method_name

  define_method method_name do |*args|
    begin
      send new_name, *args
    rescue Ironment::AccessDenied => e
      @err.puts "ironment: #{e.message}: Permission denied"
    rescue Ironment::NoEntity=> e
      @err.puts "ironment: #{e.message}: No such file or directory"
    rescue Ironment::IsDirectory=> e
      @err.puts "ironment: #{e.message}: Is a directory"
    rescue Ironment::MalformedRuncom=> e
      @err.puts "ironment: #{e.message}: Malformed runcom"
    end
  end
end

Instance Method Details

#exec_with_environment(command, *args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ironment/cl.rb', line 31

def exec_with_environment(command, *args)
  begin
    @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
end

#trust(file) ⇒ Object



47
48
49
# File 'lib/ironment/cl.rb', line 47

def trust(file)
  @ironment.trust file
end

#untrust(file) ⇒ Object



53
54
55
# File 'lib/ironment/cl.rb', line 53

def untrust(file)
  @ironment.untrust file
end