Module: Monkey::Backend

Defined in:
lib/monkey/backend.rb,
lib/monkey/backend/common/tap.rb,
lib/monkey/backend/common/parent.rb,
lib/monkey/backend/common/extract_options.rb,
lib/monkey/backend/common/singleton_class.rb

Defined Under Namespace

Modules: AbstractBackend, Common

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.available_backendsObject (readonly)

Returns the value of attribute available_backends.



7
8
9
# File 'lib/monkey/backend.rb', line 7

def available_backends
  @available_backends
end

.backendObject (readonly)

Returns the value of attribute backend.



7
8
9
# File 'lib/monkey/backend.rb', line 7

def backend
  @backend
end

Class Method Details

.detect_backend(backend_or_name) ⇒ Object

Raises:

  • (ArgumentError)


125
126
127
128
129
130
131
132
# File 'lib/monkey/backend.rb', line 125

def self.detect_backend(backend_or_name)
  return backend_or_name if backend_or_name.respond_to? :setup
  detected = available_backends.detect do |backend|
    [backend.backend_name.to_s, backend.backend_path.to_s, backend.name.to_s].include? backend_or_name.to_s
  end
  raise ArgumentError, "cannot detect backend #{backend_or_name.inspect}" unless detected
  detected
end

.new(backend_name, backend_path = nil, &block) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/monkey/backend.rb', line 77

def self.new(backend_name, backend_path = nil, &block)
  mod = eval "module #{backend_name}; self; end"
  mod.extend AbstractBackend
  backend_path ||= backend_name.to_s.downcase
  mod.backend_name, mod.backend_path = backend_name.to_s, backend_path.to_s
  available_backends << mod
  if block
    eigenclass = class << mod; self; end
    eigenclass.class_eval(&block)
  end
  mod
end

.preferred_backendObject



90
91
92
# File 'lib/monkey/backend.rb', line 90

def self.preferred_backend
  available_backends.detect { |b| b.available? } || @backend
end

.setupObject



121
122
123
# File 'lib/monkey/backend.rb', line 121

def self.setup
  setup! preferred_backend unless setup?
end

.setup!(backend) ⇒ Object Also known as: backend=



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/monkey/backend.rb', line 98

def self.setup!(backend)
  if backend
    @setup = true
    @backend = detect_backend(backend)
    @backend.setup
    @backend
  else
    available_backends.each do |backend|
      begin
        return setup!(backend)
      rescue LoadError => error
        @load_error ||= error
        @backend = nil
      end
    end  
    raise @load_error
  end
end

.setup?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/monkey/backend.rb', line 94

def self.setup?
  !!@setup
end