Method: Autumn::Leaf#database_name
- Defined in:
- lib/autumn/leaf.rb
#database_name ⇒ Object
Trues to guess the name of the database connection this leaf is using. Looks for database connections named after either this leaf’s identifier or this leaf’s class name. Returns nil if no suitable connection is found.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/autumn/leaf.rb', line 330 def database_name # :nodoc: return nil unless Module.constants.include? 'DataMapper' or Module.constants.include? :DataMapper raise "No such database connection #{options[:database]}" if [:database] and DataMapper::Repository.adapters[[:database]].nil? # Custom database connection specified return [:database].to_sym if [:database] # Leaf config name return leaf_name.to_sym if DataMapper::Repository.adapters[leaf_name.to_sym] # Leaf config name, underscored return leaf_name.methodize.to_sym if DataMapper::Repository.adapters[leaf_name.methodize.to_sym] # Leaf class name return self.class.to_s.to_sym if DataMapper::Repository.adapters[self.class.to_s.to_sym] # Leaf class name, underscored return self.class.to_s.methodize.to_sym if DataMapper::Repository.adapters[self.class.to_s.methodize.to_sym] # I give up return nil end |