Class: RTM::Engine
Instance Attribute Summary collapse
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
Class Method Summary collapse
- .[](identifier) ⇒ Object
- .abstract? ⇒ Boolean
- .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) ⇒ Object
Changed 2010-07-29: engine_name now symbols, cause, list elements are also symbol.
Instance Method Summary collapse
-
#check ⇒ Object
Check if everything is set up.
-
#identifier ⇒ Object
returns an identifier of the engine, e.g.
-
#initialize(params = {}) ⇒ Engine
constructor
A new instance of Engine.
Constructor Details
#initialize(params = {}) ⇒ Engine
Returns a new instance of Engine.
97 98 99 |
# File 'lib/rtm/engine.rb', line 97 def initialize(params={}) @params = params end |
Instance Attribute Details
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
95 96 97 |
# File 'lib/rtm/engine.rb', line 95 def connections @connections end |
Class Method Details
.[](identifier) ⇒ Object
38 39 40 |
# File 'lib/rtm/engine.rb', line 38 def self.[](identifier) all.find {|e| e.identifier == identifier} end |
.add(engine) ⇒ Object
13 14 15 16 |
# File 'lib/rtm/engine.rb', line 13 def self.add(engine) @engines ||= [] @engines << engine end |
.all ⇒ Object
28 29 30 31 32 |
# File '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 |
.connect(*args) ⇒ Object
91 92 93 |
# File 'lib/rtm/engine.rb', line 91 def self.connect(*args) self.new(*args) end |
.default ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/rtm/engine.rb', line 83 def self.default if RUBY_PLATFORM =~ /java/ :ontopia else :activerecord end end |
.detect(preferred = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rtm/engine.rb', line 68 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 |
.identifier(i = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/rtm/engine.rb', line 18 def self.identifier(i=nil) if i # setter / declaration @identifier = i else # getter @identifier end end |
.inherited(subclass) ⇒ Object
9 10 11 |
# File '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 |
.list ⇒ Object
34 35 36 |
# File 'lib/rtm/engine.rb', line 34 def self.list all.map{|e| e.identifier} end |
.load(engine_name) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File '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 |
.load!(engine_name = nil) ⇒ Object
Changed 2010-07-29: engine_name now symbols, cause, list elements are also symbol
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rtm/engine.rb', line 54 def self.load!(engine_name=nil) engine_name = self.detect unless engine_name unless list.include?(engine_name.to_sym) warn("Requested engine '#{engine_name}' not loaded. Trying to autoload it.") engine = load(engine_name.to_sym) if list.include?(engine_name.to_sym) 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.to_sym) end |
Instance Method Details
#check ⇒ Object
Check if everything is set up. This should be overwritten by backends which need special setup, like a database schema migration.
108 109 110 |
# File 'lib/rtm/engine.rb', line 108 def check true end |
#identifier ⇒ Object
returns an identifier of the engine, e.g. :ontopia or :ontopia_rdbms
102 103 104 |
# File 'lib/rtm/engine.rb', line 102 def identifier self.class.identifier end |