I think each edition will need it’s own extension title (SketchupExtension#name
) and ID (SketchupExtension#id
) and therefor their own “extension_info.txt
” file, which means their own extension registrar script, and their own extension sub-folder.
Not really necessary, but it might be possible, if the Pro edition loads after the Free edition, it could override the Free objects (classes, modules and methods,) provided that the Free objects have not yet been frozen.
Constants in Ruby are not yet “constant” and could be changed at runtime unless the last thing you do, and the end of your code is to freeze your extension sub-module for the Pro edition.
IMO, including “Pro” feature code along with a “Free/Hobby” edition is asking for a hack.
Yes it would, and Ruby is designed to help you do this using either Inheritance or Composition.
So firstly I’d suggest using composition (mixin modules), see:
Wikipedia: Composition over inheritance
An example:
Project folder structure
ene_widget_project
| # This would be the "Plugins" folder level.
| # In this folder would be each edition's
| # SketchupExtension registrar script, ie:
| "ene_widget_hobby.rb"
| "ene_widget_pro.rb"
|
+-- ene_widget_lib
| # this contains the "core" subfolder for each edition,
| # and the common 'loader' script.
| # It will be copied into each edition's extension folder,
| # when building the rbz.
|
+-- ene_widget_hobby
| # edition specific extension sub-folder and hobby code
|
+-- ene_widget_pro
# edition specific extension sub-folder and pro code
File: “ene_widget_lib/core/core_module_functions_mixin.rb
”:
(Will be copied into each edition’s extension folder.)
module Eneroth
module WidgetExtensions
module Lib
module CoreModuleFunctionsMixin
# Define core module functions common
# to both Free and Pro editions in here,
# and extend each plugin sub-module.
end
end
end
end
File: “ene_widget_lib/core/core_widget_class_mixin.rb
”:
(Will be copied into each edition’s extension folder.)
module Eneroth
module WidgetExtensions
module Lib
module CoreWidgetClassMixin
# Define core class functions common to
# both Free and Pro editions in here, and
# include in each plugin's Widget class.
end
end
end
end
File: “ene_widget_lib/widget_loader.rb
”:
(Will be copied into each edition’s extension folder.)
# This loader would be called by the edition's
# specific extension instance load() method.
module Eneroth
module WidgetExtensions
Dir::chdir(File.dirname(File.realpath(__FILE__))) {
Dir::chdir('core') {
Dir["*.{rbe,rbs,rb}"].each do |file|
# Load all the core library files in alpha order:
SketchUp::require File.basename(file,".*")
end
}
Dir["*.{rbe,rbs,rb}"].each do |file|
# Assumes 1st alpha-listed file should be loaded 1st:
SketchUp::require File.basename(file,".*")
end
}
end
end
File: “ene_widget_hobby/widget_core.rb
”:
module Eneroth
module WidgetExtensions
module WidgetHobby
Lib = Module::nesting[1]::Lib
extend Lib::CoreModuleFunctionsMixin
class Widget
include Lib::CoreWidgetClassMixin
# add any Hobby edition specific code
end
# add any Hobby edition specific code
end
end
end
File: “ene_widget_pro/widget_core.rb
”:
module Eneroth
module WidgetExtensions
module WidgetPro
Lib = Module::nesting[1]::Lib
extend Lib::CoreModuleFunctionsMixin
class Widget
include Lib::CoreWidgetClassMixin
# add any Pro edition specific code,
# or override Core inherited methods
# with only Pro functionality.
end
# add any Pro edition specific code
end
end
end
Now I only show a couple of library mixin modules (one for extending to create singleton module methods, and one for including to create instance methods,) … but you can make as many mixin modules as you need to organize and make maintenance of your project easier.