Class: Querrel::Querreller
- Inherits:
-
Object
- Object
- Querrel::Querreller
- Includes:
- MapReduce
- Defined in:
- lib/querrel/querreller.rb
Instance Attribute Summary collapse
-
#connection_resolver ⇒ Object
Returns the value of attribute connection_resolver.
Instance Method Summary collapse
-
#initialize(dbs, options = {}) ⇒ Querreller
constructor
A new instance of Querreller.
- #retrieve_connection_spec(db, resolver) ⇒ Object
- #run(options = {}, &blk) ⇒ Object
- #while_connected_to(db, resolver, &b) ⇒ Object
Methods included from MapReduce
Constructor Details
#initialize(dbs, options = {}) ⇒ Querreller
Returns a new instance of Querreller.
10 11 12 |
# File 'lib/querrel/querreller.rb', line 10 def initialize(dbs, = {}) @connection_resolver = ConnectionResolver.new(dbs, [:db_names]) end |
Instance Attribute Details
#connection_resolver ⇒ Object
Returns the value of attribute connection_resolver.
8 9 10 |
# File 'lib/querrel/querreller.rb', line 8 def connection_resolver @connection_resolver end |
Instance Method Details
#retrieve_connection_spec(db, resolver) ⇒ Object
34 35 36 |
# File 'lib/querrel/querreller.rb', line 34 def retrieve_connection_spec(db, resolver) resolver.spec(db.to_sym) end |
#run(options = {}, &blk) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/querrel/querreller.rb', line 14 def run( = {}, &blk) if .key?(:on) resolver = ConnectionResolver.new([:on], !![:db_names]) dbs = resolver.configurations.keys else resolver = @connection_resolver dbs = @connection_resolver.configurations.keys end threads = [] dbs.each do |db| threads << Thread.new do con_spec = retrieve_connection_spec(db, resolver) Thread.current[:querrel_con_spec] = con_spec yield(ConnectedModelFactory) end end threads.each(&:join) end |
#while_connected_to(db, resolver, &b) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/querrel/querreller.rb', line 38 def while_connected_to(db, resolver, &b) conf = resolver.spec(db.to_sym) pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(conf) pool.with_connection(&b) ensure pool.disconnect! end |