Module: SkippyLib::Command
- Defined in:
- modules/command.rb
Overview
A wrapper on top of UI::Command
which will automatically pick the
appropriate vector file format alternative for icon resources.
Class Method Summary collapse
- .new(title, &block) ⇒ Object
-
.set_error_handler(&block) ⇒ Object
Allows for an error handler to be configured for when commands raises an error.
Instance Method Summary collapse
- #invoke ⇒ Object
-
#large_icon=(path) ⇒ Object
Sets the large icon for the command.
- #proc ⇒ Proc
- #small_icon=(path) ⇒ Object
Class Method Details
.new(title, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'modules/command.rb', line 22 def self.new(title, &block) # SketchUp allocate the object by implementing `new` - probably part of # older legacy implementation when that was the norm. Because of that the # class cannot be sub-classed directly. This module simulates the # interface for how UI::Command is created. `new` will create an instance # of UI::Command but mix itself into the instance - effectively # subclassing it. (yuck!) command = UI::Command.new(title) { begin block.call rescue Exception => e # rubocop:disable Lint/RescueException if @error_handler.nil? raise else @error_handler.call(e) end end } command.extend(self) command.instance_variable_set(:@proc, block) command end |
.set_error_handler(&block) ⇒ Object
Allows for an error handler to be configured for when commands raises an error. Useful for providing general feedback to the user or error loggers.
16 17 18 |
# File 'modules/command.rb', line 16 def self.set_error_handler(&block) @error_handler = block end |
Instance Method Details
#invoke ⇒ Object
52 53 54 |
# File 'modules/command.rb', line 52 def invoke @proc.call end |
#large_icon=(path) ⇒ Object
Sets the large icon for the command. Provide the full path to the raster image and the method will look for a vector variant in the same folder with the same basename.
62 63 64 |
# File 'modules/command.rb', line 62 def large_icon=(path) super(Resource.icon_path(path)) end |
#proc ⇒ Proc
47 48 49 |
# File 'modules/command.rb', line 47 def proc @proc end |