Class: MDS::Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/mds/backend.rb

Overview

Provides a common interface to matrix operations.

Class Method Summary collapse

Class Method Details

.activeObject

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

.availableObject

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_activeObject

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.

Parameters:

  • String

    path the path or globbing expression to pass to require



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.expand_path(path)) do |path|
    begin
      require path
    rescue LoadError
    end
  end
end