Class: Unisms::Router::Random
- Defined in:
- lib/unisms/router/random.rb,
lib/unisms/router/random.rb
Instance Attribute Summary collapse
-
#adapters ⇒ Object
Returns the value of attribute adapters.
Instance Method Summary collapse
-
#initialize(adapters = nil) ⇒ Random
constructor
A new instance of Random.
- #load_internal_adapters ⇒ Object
- #route ⇒ Object
Methods inherited from Base
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
#adapters ⇒ Object
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_adapters ⇒ Object
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 |
#route ⇒ Object
11 12 13 |
# File 'lib/unisms/router/random.rb', line 11 def route @adapters.sample end |