Module: Interchange::Methods

Defined in:
lib/interchange.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



66
67
68
69
# File 'lib/interchange.rb', line 66

def check
  fail NotAvailableError, implementation unless up?
  true
end

#down?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/interchange.rb', line 62

def down?
  !up?
end

#implementationObject



75
76
77
# File 'lib/interchange.rb', line 75

def implementation
  @implementation
end

#implementationsObject



71
72
73
# File 'lib/interchange.rb', line 71

def implementations
  @implementations ||= { }
end

#register(name, implementation) ⇒ Object



43
44
45
# File 'lib/interchange.rb', line 43

def register(name, implementation)
  implementations[name] = implementation
end

#use(name) ⇒ Object



47
48
49
50
51
# File 'lib/interchange.rb', line 47

def use(name)
  @implementation = implementations.fetch name do
    raise UnregisteredError, name
  end
end

#with(name) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/interchange.rb', line 53

def with(name)
  original = implementation
  use name
  result = yield self
  @implementation = original

  result
end