Class: MDS::Backend
- Inherits:
-
Object
- Object
- MDS::Backend
- Defined in:
- lib/mds/backend.rb
Overview
Provides a common interface to matrix operations.
Class Method Summary collapse
-
.active ⇒ Object
Access the active matrix interface.
-
.active=(i) ⇒ Object
Set the active matrix interface.
-
.add(i) ⇒ Object
Add available interface class.
-
.available ⇒ Object
Return available interface classes.
-
.first(search_order = MDS::PREFERRED_INTERFACE_ORDER) ⇒ Object
Return the first interface class.
-
.pop_active ⇒ Object
Deactivate active matrix interface by popping it from stack.
-
.push_active(i) ⇒ Object
Push matrix interface onto the stack and set it active.
-
.try_require(path = File.join(File.dirname(__FILE__), 'interfaces', '*interface.rb')) ⇒ Object
Require all interfaces from path and conceal possible errors.
Class Method Details
.active ⇒ Object
Access the active matrix interface.
25 26 27 |
# File 'lib/mds/backend.rb', line 25 def active @active.first; end |
.active=(i) ⇒ Object
Set the active matrix interface.
32 33 34 35 |
# File 'lib/mds/backend.rb', line 32 def active=(i) @active.pop @active.push(i) end |
.add(i) ⇒ Object
Add available interface class.
Automatically called when interface is required.
56 57 58 |
# File 'lib/mds/backend.rb', line 56 def add(i) @available << i end |
.available ⇒ Object
Return available interface classes.
63 64 65 |
# File 'lib/mds/backend.rb', line 63 def available @available end |
.first(search_order = MDS::PREFERRED_INTERFACE_ORDER) ⇒ Object
Return the first interface class.
If no interface class matches a string in search_order
, the first available interface is returned.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/mds/backend.rb', line 73 def first(search_order = MDS::PREFERRED_INTERFACE_ORDER) c = search_order.map do |name| begin name.split('::').inject(Kernel) do |scope, const_name| scope.const_get(const_name) end rescue NameError nil end end.compact! (!c || c.length == 0) ? @available.first : c.first end |
.pop_active ⇒ Object
Deactivate active matrix interface by popping it from stack.
47 48 49 |
# File 'lib/mds/backend.rb', line 47 def pop_active @active.pop() end |
.push_active(i) ⇒ Object
Push matrix interface onto the stack and set it active.
40 41 42 |
# File 'lib/mds/backend.rb', line 40 def push_active(i) @active.push(i) end |
.try_require(path = File.join(File.dirname(__FILE__), 'interfaces', '*interface.rb')) ⇒ Object
Require all interfaces from path and conceal possible errors.
92 93 94 95 96 97 98 99 |
# File 'lib/mds/backend.rb', line 92 def try_require(path = File.join(File.dirname(__FILE__), 'interfaces', '*interface.rb')) Dir.glob(File.(path)) do |path| begin require path rescue LoadError end end end |