Module: MyPKI::Prompter

Included in:
CA, Configuration, P12, PEM, SSH
Defined in:
lib/mypki/prompter.rb,
lib/mypki/prompters/cli.rb,
lib/mypki/prompters/iruby.rb,
lib/mypki/prompters/jruby.rb

Defined Under Namespace

Classes: CommandLinePrompter, IRubyPrompter, JRubyPrompter

Instance Method Summary collapse

Instance Method Details

#file_prompt(prompt, required: true) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mypki/prompter.rb', line 18

def file_prompt prompt, required: true
  file = prompter.file_prompt(prompt)

  if file.nil? or file.empty?
    required ? fail('cancelled') : nil
  else
    expanded = File.expand_path file.strip
            
    if File.directory? expanded
      fail "'#{expanded}' is a directory"
    end
    
    unless File.readable? expanded
      fail "Cannot read '#{expanded}'"
    end
    
    expanded
  end
end

#pass_prompt(prompt) ⇒ Object



38
39
40
41
# File 'lib/mypki/prompter.rb', line 38

def pass_prompt prompt
  pass = prompter.pass_prompt(prompt)
  pass.strip if pass
end

#prompterObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mypki/prompter.rb', line 5

def prompter 
  if defined? IRuby and defined? IRuby::VERSION
    require 'mypki/prompters/iruby'
    @prompter = IRubyPrompter.new
  elsif RUBY_PLATFORM == 'java'
    require 'mypki/prompters/jruby'
    @prompter = JRubyPrompter.new
  else
    require 'mypki/prompters/cli'
    @prompter = CommandLinePrompter.new
  end
end