@jim said:
What about creating an abstract base class named Plugin which provides inspectors for the information? Not only could inspectors be created for name, author, copyright, license, etc; but also inspectors for menus, Commands and toolbar images?
This way, external applications (menu organizers, etc) can simply ask the plugin about itself.
I've actually done some playing around & testing this past week along these lines, before I saw this post.
I had seen, in many standard (extra Sketchup) ruby scripts, that coders were just declaring a string constant "VERSION" at the top of their outer code blocks. This could be easily accessed ie:, Module::VERSION.
But then the spark for me was seeing somewhere (perhaps within the RubyGems files,) someone took it a baby step forward by making the constant VERSION a Hash with 4 elements, the first 3 Integer components of the version number, and the 4th a string concatonation of the first 3. ie:
VERSION=[MAJOR => 0, MINOR => 0, TEENY => 0, STRING => (MAJOR,MINOR,TEENY).join(".") ]
This was a bit better, as you could get any one of the version components for comparison, without having to convert to numeric, by calling as an example:
if Module;;VERSION[MAJOR] < 7 {..do a block..}
Or if you wanted the whole version string, you'd call, like so:
messagebox( "The plugin version is; #{Module;;VERSION[STRING]}" )
But the spark had not yet ignited into flame until I stumbled across the standard ruby class OpenStruct. When I read the filenotes in 'ostruct.rb', I immediately thought this is perfect for versioning !!
OpenStruct is similar to the built-in class Struct, but really makes it act like a true data object should act in an object oriented language like Ruby. Struct on the other hand is so much like a hash, there doesn't seem to be much benefit in it; as you still set and access values as you would in a hash object.
OpenStruct is SO MUCH better! You simply state a new object name = followed by OpenStruct.new(keylist), where the keylist is just that; a list of data keys to create. The class creates all the keys as attributes, and automatically sets up getter and setter accessors for each one!
(Pssst! [whispering off topic this would also be great for ruby-side JSON as OpenStructs will look and act just like Javascript Objects..)]
So my thoughts are to set up a custom subclass of OpenStruct called VersionStruct, or just a custom class called VersionStruct that uses an OpenStruct. Still playing and testing which way is better. Any way the goal is to have something that is all setup correctly that can be either 'included' or mixed-in into a top code block, so the module or class inherits the data structure; OR instanstiated into a code block if it's set up as a class. (I cannot see making coders cut and paste a codeblock into everyscript, errors may creep in.) Anyway.. after instantiating a VersionStruct, a coder would set the fields, then freeze the VERSION object (so the data cannot be changed after the script is loaded.)
Example: ['RubyTools' is a fictional Namespace.]
module DandyCode
VERSION = RubyTools;;VersionStruct.new(2,1,4)
# first 3 parameters are integers; major, minor, teeny
# note VERSION.string is created automatically
VERSION.author="Ruby A. Coder"
VERSION.copyright="(c) 2010 by author"
VERSION.disclaimer="No Waranty...no particular purpose...author to be held harmless ...etc" # can be preset
VERSION.termsOfUse="Free for Public Use...etc." # can be preset
VERSION.title="Title of this plugin code"
VERSION.description="A short explanation of it's features."
VERSION.minSUverMajor=7
VERSION.minSUverMinor=1
VERSION.dependancies=self.DependancyList
VERSION.exclusions=self.ExclusionList
VERSION.freeze
DependancyList = Array.new
DependancyList[0] = DependancyItemStruct.new(module='JRF;;Inputbox', minverMajor=2)
ExclusionList = Array.new
ExclusionList[0] = ExclusionItemStruct.new(module='SluggishKeyTrapper', allVers=true)
VERSION.freeze
.. more code ...
end # module
Anyway.. ideas to chew on...
Currently.. I'm only playing with a VERSION structure that has Major, Minor, Teeny and String attributes.
The other attributes in the above example, or discussed in the prior posts, could be in a separate struct as Jim suggested called 'Plugin' or whatever. (We've seen a similar thing done with the Sketchup Extension Class, except that it's put in a separate file.)
For those interested, who don't have a full ruby install, I attach the ostruct.rb file that ships with Ruby 1.9.1 (put it in a folder that's in the search path, perhaps the Tools folder. I personally have it in a folder named 'Library' which I put in my search path.)
ostruct.rb