Class: RubyAppraiser::Adapter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby-appraiser/adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(appraisal, options) ⇒ Adapter

Returns a new instance of Adapter.



62
63
64
65
# File 'lib/ruby-appraiser/adapter.rb', line 62

def initialize(appraisal, options)
  @appraisal = appraisal
  @options = options.dup
end

Class Method Details

.adapter_type(type = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby-appraiser/adapter.rb', line 16

def adapter_type(type = nil)
  @adapter_type = type.to_s unless type.nil?

  @adapter_type or
    self.name.split('::').last.
      sub(/Adapter$/, '').
      gsub(/[A-Z]+/, '-\0').
      sub(/^-/, '').
      downcase
end

.allObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby-appraiser/adapter.rb', line 40

def all
  # load relevant gems
  scanner_pattern = /^(ruby-appraiser-([a-zA-Z0-9_\-]+))/
  (`gem list --local`).scan(scanner_pattern) do |gem_name, adapter_type|
    attempt_require_adapter(adapter_type, gem_name)
  end

  # return the registry
  registry
end

.attempt_require_adapter(name, path) ⇒ Object



51
52
53
54
55
# File 'lib/ruby-appraiser/adapter.rb', line 51

def attempt_require_adapter(name, path)
  require path and find(name)
rescue LoadError
  false
end

.find(query) ⇒ Object



27
28
29
30
31
# File 'lib/ruby-appraiser/adapter.rb', line 27

def find(query)
  registry.detect do |adapter|
    adapter.adapter_type == query
  end
end

.find!(query) ⇒ Object



57
58
59
# File 'lib/ruby-appraiser/adapter.rb', line 57

def find!(query)
  find(query) or raise ArgumentError, "Adapter '#{query}' not found."
end

.get(query) ⇒ Object



33
34
35
36
37
38
# File 'lib/ruby-appraiser/adapter.rb', line 33

def get(query)
  find(query) or
    attempt_require_adapter(query, "ruby-appraiser/adapter/#{query}") or
    attempt_require_adapter(query, "ruby-appraiser/#{query}") or
    attempt_require_adapter(query, "ruby-appraiser-#{query}")
end

.inherited(base) ⇒ Object



8
9
10
# File 'lib/ruby-appraiser/adapter.rb', line 8

def inherited(base)
  registry << base
end

.registryObject



12
13
14
# File 'lib/ruby-appraiser/adapter.rb', line 12

def registry
  @registry ||= Set.new
end

Instance Method Details

#appraiseObject

Raises:

  • (NotImplementedError)


67
68
69
70
# File 'lib/ruby-appraiser/adapter.rb', line 67

def appraise
  raise NotImplementedError,
        "#{self.class.name} does not implement appraise."
end