Pushes the named database onto the context-stack, yields a new session, and pops the context-stack.
results = DataMapper.database(:second_database) do |current_context| ... end
Returns the current session, or if there is none, a new Session.
current_database = DataMapper.database
# File lib/data_mapper/database.rb, line 26 26: def self.database(name = :default) # :yields: current_context 27: unless block_given? 28: Database.context.last || Context.new(Database[name].adapter) 29: else 30: begin 31: Database.context.push(Context.new(Database[name].adapter)) 32: return yield(Database.context.last) 33: ensure 34: Database.context.pop 35: end 36: end 37: end
Pushes the named database onto the context-stack, yields a new session, and pops the context-stack.
results = DataMapper.database(:second_database) do |current_context| ... end
Returns the current session, or if there is none, a new Session.
current_database = DataMapper.database
# File lib/data_mapper/database.rb, line 26 26: def self.database(name = :default) # :yields: current_context 27: unless block_given? 28: Database.context.last || Context.new(Database[name].adapter) 29: else 30: begin 31: Database.context.push(Context.new(Database[name].adapter)) 32: return yield(Database.context.last) 33: ensure 34: Database.context.pop 35: end 36: end 37: end