Class: RTM::Engine
- Inherits:
-
Object
- Object
- RTM::Engine
- Includes:
- TopicMapSystem
- Defined in:
- rtm/lib/rtm/engine.rb,
rtm/spec/rtm/engine_spec.rb
Direct Known Subclasses
Instance Attribute Summary
-
- (Object) connections
readonly
Returns the value of attribute connections.
Class Method Summary
- + (Object) [](identifier)
- + (Boolean) abstract?
- + (Object) add(engine)
- + (Object) all
- + (Object) connect(*args)
- + (Object) default
- + (Object) detect(preferred = nil)
- + (Object) identifier(i = nil)
- + (Object) inherited(subclass)
- + (Object) list
- + (Object) load(engine_name)
- + (Object) load!(engine_name = nil)
Instance Method Summary
-
- (Object) check
Check if everything is set up.
-
- (Object) identifier
returns an identifier of the engine, e.g.
-
- (Engine) initialize(params = {})
constructor
A new instance of Engine.
Constructor Details
- (Engine) initialize(params = {})
A new instance of Engine
96 97 98 |
# File 'rtm/lib/rtm/engine.rb', line 96 def initialize(params={}) @params = params end |
Instance Attribute Details
- (Object) connections (readonly)
Returns the value of attribute connections
94 95 96 |
# File 'rtm/lib/rtm/engine.rb', line 94 def connections @connections end |
Class Method Details
+ (Object) [](identifier)
38 39 40 |
# File 'rtm/lib/rtm/engine.rb', line 38 def self.[](identifier) all.find {|e| e.identifier == identifier} end |
+ (Boolean) abstract?
5 6 7 |
# File 'rtm/lib/rtm/engine.rb', line 5 def self.abstract? self == Engine end |
+ (Object) add(engine)
13 14 15 16 |
# File 'rtm/lib/rtm/engine.rb', line 13 def self.add(engine) @engines ||= [] @engines << engine end |
+ (Object) all
28 29 30 31 32 |
# File 'rtm/lib/rtm/engine.rb', line 28 def self.all @engines ||= [] @engines.reject!{|e| e.abstract?} # this needs to be done here because in the inherited hook the method is not yet available. @engines end |
+ (Object) connect(*args)
90 91 92 |
# File 'rtm/lib/rtm/engine.rb', line 90 def self.connect(*args) self.new(*args) end |
+ (Object) default
82 83 84 85 86 87 88 |
# File 'rtm/lib/rtm/engine.rb', line 82 def self.default if RUBY_PLATFORM =~ /java/ :ontopia else :activerecord end end |
+ (Object) detect(preferred = nil)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'rtm/lib/rtm/engine.rb', line 67 def self.detect(preferred=nil) if preferred # return the users preference, if given implementation = preferred elsif engine_name = ENV['RTM_BACKEND'] || ENV['RTM_IMPLEMENTATION'] || ENV['RTM_ENGINE'] # inspect system environment (several alternatives) implementation = engine_name.to_sym elsif implementation = self.list.first # check if one is already loaded warn("No engine implementation was specified for RTM.connect. Using the first already loaded engine (#{implementation.inspect}).") else implementation = self.default # use hardcoded default warn("No engine implementation was specified for RTM.connect. Choosing default (#{implementation.inspect}).") implementation end implementation end |
+ (Object) identifier(i = nil)
18 19 20 21 22 23 24 25 26 |
# File 'rtm/lib/rtm/engine.rb', line 18 def self.identifier(i=nil) if i # setter / declaration @identifier = i else # getter @identifier end end |
+ (Object) inherited(subclass)
9 10 11 |
# File 'rtm/lib/rtm/engine.rb', line 9 def self.inherited(subclass) Engine.add(subclass) # this MUST be Engine and not self! Otherwise every intermediate class in the inheritance chain will have it's own list end |
+ (Object) list
34 35 36 |
# File 'rtm/lib/rtm/engine.rb', line 34 def self.list all.map{|e| e.identifier} end |
+ (Object) load(engine_name)
42 43 44 45 46 47 48 49 50 51 |
# File 'rtm/lib/rtm/engine.rb', line 42 def self.load(engine_name) engine_gem_name = engine_name engine_gem_name = engine_name.to_s.split("_").first if engine_gem_name.to_s =~ /_/ unless Object.const_defined?("Gem") && rtmgem = Gem.loaded_specs["rtm"] engine_path = File.(File.join(File.dirname(__FILE__), "../../../rtm-#{engine_gem_name}/lib")) $LOAD_PATH.unshift engine_path if File.directory?(engine_path) end require "rtm/#{engine_gem_name}" self[engine_name] end |
+ (Object) load!(engine_name = nil)
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'rtm/lib/rtm/engine.rb', line 53 def self.load!(engine_name=nil) engine_name = self.detect unless engine_name unless list.include?(engine_name) warn("Requested engine '#{engine_name}' not loaded. Trying to autoload it.") engine = load(engine_name) if list.include?(engine_name) warn("Autoloading '#{engine_name}' was successful") else raise "Autoloading '#{engine_name}' failed. Make sure rtm-#{engine_name} exists and is installed or require it manually." end end engine || load(engine_name) end |
Instance Method Details
- (Object) check
Check if everything is set up. This should be overwritten by backends which need special setup, like a database schema migration.
107 108 109 |
# File 'rtm/lib/rtm/engine.rb', line 107 def check true end |
- (Object) identifier
returns an identifier of the engine, e.g. :ontopia or :ontopia_rdbms
101 102 103 |
# File 'rtm/lib/rtm/engine.rb', line 101 def identifier self.class.identifier end |