Class: Palaver::DialogFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/palaver/dialog_factory.rb

Constant Summary collapse

@@dialog_types =
{
  :calendar => Calendar,
  :checklist => Checklist,
  :radiolist => Radiolist,
  :menu => Menu,
  :yesno => YesNo,
  :textbox => TextBox,
  :msgbox => MsgBox,
  :inputbox => InputBox,
  :infobox => InfoBox,
  :pause => Pause,
  :passwordbox => PasswordBox,
  :dselect => DSelect,
  :fselect => FSelect,
  :form => Form,
  :passwordform => PasswordForm,
  :gauge => Gauge
}

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ DialogFactory

Returns a new instance of DialogFactory.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/palaver/dialog_factory.rb', line 25

def initialize(*options)
  options.each do |option|
    case option
    when :insecure then @insecure = true
    when :ascii_lines then @ascii_lines = true
    when :no_lines then @no_lines = true
    end

    if option.class == Hash then
      option.each do |k,v|
        case k
          when :aspect then @aspect = v
          when :backtitle then @backtitle = v
          when :begin then @begin = v
          when :cancel_label then @cancel_label = v
        end
      end
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodsym, *args, &block) ⇒ Object (private)



60
61
62
63
64
65
66
67
68
69
# File 'lib/palaver/dialog_factory.rb', line 60

def method_missing(methodsym, *args, &block)
  if @@dialog_types.has_key? methodsym then
    c = @@dialog_types[methodsym]
    options = args.size == 1 ? args[0] : {}
    options[:common_options] = common_options
    return make_dialog(c, options, &block)
  else
    raise NoMethodError.new("Undefined method: #{methodsym} for #{self}", methodsym)
  end
end

Instance Method Details

#common_optionsObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/palaver/dialog_factory.rb', line 46

def common_options
  options = []
  options.push("--insecure") if @insecure
  options.push("--ascii-lines") if @ascii_lines
  options.push("--no-lines") if @no_lines
  options.push("--aspect #@aspect") if @aspect
  options.push("--backtitle '#@backtitle'") if @backtitle
  options.push("--begin #{@begin[0]} #{@begin[1]}") if @begin
  options.push("--cancel-label '#@cancel_label'") if @cancel_label
  return options.join(" ")
end