Class: Dialog::DialogOptions
- Inherits:
-
Object
- Object
- Dialog::DialogOptions
- Defined in:
- lib/base.rb
Overview
Base class collecting common options and handlers for a dialog
Instance Attribute Summary collapse
-
#box_options ⇒ Object
readonly
Returns the value of attribute box_options.
-
#common_options ⇒ Object
readonly
Returns the value of attribute common_options.
-
#handlers ⇒ Object
readonly
Returns the value of attribute handlers.
Instance Method Summary collapse
-
#cancel(label = "Cancel", &block) ⇒ Object
Sets the label for the cancel button and optionally attaches a block as cancel handler.
-
#dup ⇒ Object
Creates a semi-shallow copy of the object.
-
#extra(label = "Rename", &block) ⇒ Object
Sets the label for the extra button and optionally attaches a block as extra handler.
-
#height(h) ⇒ Object
Sets the dialog’s height.
-
#help(&block) ⇒ Object
Attaches a block as help handler.
-
#initialize(height = 0, width = 0) {|_self| ... } ⇒ DialogOptions
constructor
Initializes the collector with default options.
-
#method_missing(name, *args) ⇒ Object
Map unknown method names to common options.
-
#no(label = "No", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler.
-
#ok(label = "OK", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler.
-
#text(t) ⇒ Object
Sets the dialog’s text.
-
#width(w) ⇒ Object
Sets the dialog’s width.
-
#yes(label = "Yes", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler.
Constructor Details
#initialize(height = 0, width = 0) {|_self| ... } ⇒ DialogOptions
Initializes the collector with default options.
20 21 22 23 24 25 |
# File 'lib/base.rb', line 20 def initialize(height = 0, width = 0) @handlers = {} @box_options = ["Er, perhaps you should set some text using the text method!", height, width] @common_options = {} yield self if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Map unknown method names to common options
80 81 82 |
# File 'lib/base.rb', line 80 def method_missing(name, *args) @common_options.store(name.to_s.gsub('_','-'), args); end |
Instance Attribute Details
#box_options ⇒ Object
Returns the value of attribute box_options.
17 18 19 |
# File 'lib/base.rb', line 17 def @box_options end |
#common_options ⇒ Object
Returns the value of attribute common_options.
17 18 19 |
# File 'lib/base.rb', line 17 def @common_options end |
#handlers ⇒ Object
Returns the value of attribute handlers.
17 18 19 |
# File 'lib/base.rb', line 17 def handlers @handlers end |
Instance Method Details
#cancel(label = "Cancel", &block) ⇒ Object
Sets the label for the cancel button and optionally attaches a block as cancel handler
46 47 48 49 |
# File 'lib/base.rb', line 46 def cancel(label="Cancel", &block) @common_options.store('cancel-label', label) @handlers[:cancel] = block end |
#dup ⇒ Object
Creates a semi-shallow copy of the object
The object and its immediate data structures are copied. The instances they refer to, however, are not.
88 89 90 91 92 93 94 |
# File 'lib/base.rb', line 88 def dup opts = DialogOptions.new opts. = @box_options.dup opts.handlers = @handlers.dup opts. = @common_options.dup opts end |
#extra(label = "Rename", &block) ⇒ Object
Sets the label for the extra button and optionally attaches a block as extra handler
52 53 54 55 56 |
# File 'lib/base.rb', line 52 def extra(label="Rename", &block) @common_options.store('extra-button', nil) @common_options.store('extra-label', label) @handlers[:extra] = block end |
#height(h) ⇒ Object
Sets the dialog’s height
70 71 72 |
# File 'lib/base.rb', line 70 def height(h) @box_options[1] = h end |
#help(&block) ⇒ Object
Attaches a block as help handler. No label can be specified, because help is hardwired to F1.
59 60 61 62 |
# File 'lib/base.rb', line 59 def help(&block) @common_options.store('help-button', nil) @handlers[:help] = block end |
#no(label = "No", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler
34 35 36 37 |
# File 'lib/base.rb', line 34 def no(label="No", &block) @common_options.store('no-label', label) @handlers[:no] = block end |
#ok(label = "OK", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler
40 41 42 43 |
# File 'lib/base.rb', line 40 def ok(label="OK", &block) @common_options.store('ok-label', label) @handlers[:ok] = block end |
#text(t) ⇒ Object
Sets the dialog’s text
75 76 77 |
# File 'lib/base.rb', line 75 def text(t) @box_options[0] = t end |
#width(w) ⇒ Object
Sets the dialog’s width
65 66 67 |
# File 'lib/base.rb', line 65 def width(w) @box_options[2] = w end |
#yes(label = "Yes", &block) ⇒ Object
Sets the label for the ok button and optionally attaches a block as ok handler
28 29 30 31 |
# File 'lib/base.rb', line 28 def yes(label="Yes", &block) @common_options.store('yes-label', label) @handlers[:yes] = block end |