Class: RRT_RUBY::RRTGeneric::Finder
- Inherits:
-
Object
- Object
- RRT_RUBY::RRTGeneric::Finder
- Includes:
- RivaLib::RivaLogger
- Defined in:
- lib/rrt_ruby/rrt_generic.rb
Overview
Finder provides an interface for accessing RRT models using OLE Automation. Finder represents a read-only interface to a model’s content, and will remain so in future versions.
It will create an OLE Instance of RRT on initialization.
In order to properly release this instance Finder#stop must be called prior to exiting the Ruby application.
Alternatively Finder#open can be used with a block.
RRT under Windows XP (not tested on other versions) only allows three instances. Unfortunately, once an OLE Automation instance is accessed, references prevent the instances from being destroyed even after stopping a Finder.
This effectively limits the number of possible Finder instances per application to three.
Notice that you still need to call stop or use open with a block otherwise the RRT application will remain in memory after termination of the Ruby application.
Direct Known Subclasses
RRT_RUBY::RRTComponent::ComponentFinder, RRT_RUBY::RRTDeployment::DeploymentFinder, RRT_RUBY::RRTFinder, RRT_RUBY::RRTLogical::LogicalFinder
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#modelname ⇒ Object
readonly
Returns the value of attribute modelname.
Attributes included from RivaLib::RivaLogger
Class Method Summary collapse
-
.open(modelname, logger = nil) ⇒ Object
open is used in conjuction with a block.
Instance Method Summary collapse
-
#hide ⇒ Object
Hides the RRT UI for the associated OLE instance.
-
#initialize(modelname = "", logger = nil) ⇒ Finder
constructor
Initialize will throw an exception if the model cannot be opened.
-
#name ⇒ Object
returns the name of the model with which the finder is connected Alias for LogicalFinder#modelname.
-
#reload(modelname) ⇒ Object
Instructs the Finder to load a new model into it’s associated RRT instance.
-
#show ⇒ Object
Shows the RRT UI for the associated OLE instance Makes the RRT UI associated with the Finder visible.
-
#stop ⇒ Object
Stops the Finder releasing the OLE interface and invalidating this Finder instance.
- #to_s ⇒ Object
Methods included from RivaLib::RivaLogger
Constructor Details
#initialize(modelname = "", logger = nil) ⇒ Finder
Initialize will throw an exception if the model cannot be opened.
Finder uses Logger to log on STDOUT. Optionally you can pass a Logger instance and it will be used.
61 62 63 64 65 66 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 61 def initialize modelname="",logger=nil @modelname=modelname @app=WIN32OLE.new(RRTGeneric::OLEAPP_NAME) @model=@app.OpenModel(@modelname) unless modelname.empty? logger_init(logger) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
56 57 58 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 56 def model @model end |
#modelname ⇒ Object (readonly)
Returns the value of attribute modelname.
56 57 58 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 56 def modelname @modelname end |
Class Method Details
.open(modelname, logger = nil) ⇒ Object
open is used in conjuction with a block.
It creates a Finder instance and passes it to the block. At the end of the block the Finder is stopped and invalidated.
You can optionally pass a Logger instance to be used by the Finder.
Without a block the method is just an alias for Finder#new
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 75 def Finder.open modelname,logger=nil begin fndr=new(modelname,logger) if block_given? begin yield fndr ensure fndr.stop end else return fndr end end end |
Instance Method Details
#hide ⇒ Object
Hides the RRT UI for the associated OLE instance.
Throws a FinderException if no instance exists
128 129 130 131 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 128 def hide raise FinderException.new(@modelname),"This Finder instance is invalid" unless @model @app.visible=false end |
#name ⇒ Object
returns the name of the model with which the finder is connected Alias for LogicalFinder#modelname
134 135 136 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 134 def name return @modelname end |
#reload(modelname) ⇒ Object
Instructs the Finder to load a new model into it’s associated RRT instance.
If modelname matches the current modelname or the Finder is invalid…well, nothing will happen.
92 93 94 95 96 97 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 92 def reload modelname begin @modelname=modelname @model=@app.openmodel(@modelname) end if @app && @app.CurrentModel.GetFileName.upcase!=modelname.upcase end |
#show ⇒ Object
Shows the RRT UI for the associated OLE instance Makes the RRT UI associated with the Finder visible.
Throws a FinderException if no instance exists
121 122 123 124 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 121 def show raise FinderException.new(@modelname),"This Finder instance is invalid" unless @model @app.visible=true end |
#stop ⇒ Object
Stops the Finder releasing the OLE interface and invalidating this Finder instance.
This method must be called to clean up resources unless you used Finder#start with a block.
If you don’t call this method you will end up with a zombie RoserRT instance and a couple of MBs less memory.
After calling stop the Finder instance cannot be used again (most methods throw a FinderException).
Unfortunately, there is no control on when the RRT instance is going to exit.
Usually RRT instances that have been accessed will not exit until the application/script ends. Since RRT only allows three running instances, this means you can only reload a stopped finder twice.
110 111 112 113 114 115 116 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 110 def stop @logger.debug("Stopping Finder") @app.exit if @app @app.ole_free() @model=nil @app=nil end |
#to_s ⇒ Object
137 138 139 140 |
# File 'lib/rrt_ruby/rrt_generic.rb', line 137 def to_s return "Active on #{@modelname}" if @model return "Invalid for #{@modelname}" end |