Class: Unisms::Router::Random

Inherits:
Base
  • Object
show all
Defined in:
lib/unisms/router/random.rb,
lib/unisms/router/random.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#deliver

Constructor Details

#initialize(adapters = nil) ⇒ Random

Returns a new instance of Random.



7
8
9
# File 'lib/unisms/router/random.rb', line 7

def initialize(adapters = nil)
	@adapters = adapters.is_a?(Array) ? adapters : [adapters].compact
end

Instance Attribute Details

#adaptersObject

Returns the value of attribute adapters.



5
6
7
# File 'lib/unisms/router/random.rb', line 5

def adapters
  @adapters
end

Instance Method Details

#load_internal_adaptersObject



19
20
21
22
23
# File 'lib/unisms/router/random.rb', line 19

def load_internal_adapters
	adapter_module = Unisms::Adapter
	klasses = adapter_module.constants.reject{ |c| c == :Base }.select { |c| adapter_module.const_get(c).is_a? Class }.map {|c| adapter_module.const_get c }
	@adapters = klasses.map { |klass| klass.new rescue nil }.compact
end

#routeObject



11
12
13
# File 'lib/unisms/router/random.rb', line 11

def route
	@adapters.sample
end