The path used to require the in memory adapter
@see DataMapper.setup
@return [String]
the path used to require the desired in memory adapter
@api semipublic
# File lib/dm-core/adapters.rb, line 40 40: def self.in_memory_adapter_path 41: @in_memory_adapter_path ||= 'dm-core/adapters/in_memory_adapter' 42: end
The path used to require the in memory adapter
Set this if you want to register your own adapter to be used when you specify an ‘in_memory’ connection during
@see DataMapper.setup
@param [String] path
the path used to require the desired in memory adapter
@api semipublic
# File lib/dm-core/adapters.rb, line 28 28: def self.in_memory_adapter_path=(path) 29: @in_memory_adapter_path = path 30: end
Set up an adapter for a storage engine
@see DataMapper.setup
@api private
# File lib/dm-core/adapters.rb, line 11 11: def self.new(repository_name, options) 12: options = normalize_options(options) 13: adapter_class(options.fetch(:adapter)).new(repository_name, options) 14: end
Return the adapter class constant
@example
DataMapper::Adapters.send(:adapter_class, 'mysql') # => DataMapper::Adapters::MysqlAdapter
@param [Symbol] name
the name of the adapter
@return [Class]
the AbstractAdapter subclass
@api private
# File lib/dm-core/adapters.rb, line 130 130: def adapter_class(name) 131: adapter_name = normalize_adapter_name(name) 132: class_name = (DataMapper::Inflector.camelize(adapter_name) << 'Adapter').to_sym 133: load_adapter(adapter_name) unless const_defined?(class_name) 134: const_get(class_name) 135: end
Return the name of the adapter
@example
DataMapper::Adapters.adapter_name('MysqlAdapter') # => 'mysql'
@param [String] const_name
the adapter constant name
@return [String]
the name of the adapter
@api semipublic
# File lib/dm-core/adapters.rb, line 149 149: def adapter_name(const_name) 150: const_name.to_s.chomp('Adapter').downcase 151: end
Returns wether or not the given adapter name is considered an in memory adapter
@param [String, Symbol] name
the name of the adapter
@return [Boolean]
true if the adapter is considered to be an in memory adapter
@api private
# File lib/dm-core/adapters.rb, line 181 181: def in_memory_adapter?(name) 182: name.to_s == 'in_memory' 183: end
Returns the fallback filename that would be used to require the named adapter
The fallback format is “#{name}_adapter” and will be phased out in favor of the properly ‘namespaced’ “dm-#{name}-adapter” format.
@param [String, Symbol] name
the name of the adapter to require
@return [String]
the filename that gets required for the adapter identified by name
@api private
# File lib/dm-core/adapters.rb, line 197 197: def legacy_path(name) 198: "#{name}_adapter" 199: end
Require the adapter library
@param [String, Symbol] name
the name of the adapter
@return [Boolean]
true if the adapter is loaded
@api private
# File lib/dm-core/adapters.rb, line 162 162: def load_adapter(name) 163: require "dm-#{name}-adapter" 164: rescue LoadError => original_error 165: begin 166: require in_memory_adapter?(name) ? in_memory_adapter_path : legacy_path(name) 167: rescue LoadError 168: raise original_error 169: end 170: end
Adjust the adapter name to match the name used in the gem providing the adapter
@param [String, Symbol] name
the name of the adapter
@return [String]
the normalized adapter name
@api private
# File lib/dm-core/adapters.rb, line 210 210: def normalize_adapter_name(name) 211: (original = name.to_s) == 'sqlite3' ? 'sqlite' : original 212: end
Normalize the arguments passed to new()
Turns options hash or connection URI into the options hash used by the adapter.
@param [Hash, Addressable::URI, String] options
the options to be normalized
@return [Mash]
the options normalized as a Mash
@api private
# File lib/dm-core/adapters.rb, line 59 59: def normalize_options(options) 60: case options 61: when Hash then normalize_options_hash(options) 62: when Addressable::URI then normalize_options_uri(options) 63: when String then normalize_options_string(options) 64: else 65: assert_kind_of 'options', options, Hash, Addressable::URI, String 66: end 67: end
Normalize Hash options into a Mash
@param [Hash] hash
the hash to be normalized
@return [Mash]
the options normalized as a Mash
@api private
# File lib/dm-core/adapters.rb, line 78 78: def normalize_options_hash(hash) 79: DataMapper::Ext::Hash.to_mash(hash) 80: end
Normalize String options into a Mash
@param [String] string
the string to be normalized
@return [Mash]
the options normalized as a Mash
@api private
# File lib/dm-core/adapters.rb, line 114 114: def normalize_options_string(string) 115: normalize_options_uri(Addressable::URI.parse(string)) 116: end
Normalize Addressable::URI options into a Mash
@param [Addressable::URI] uri
the uri to be normalized
@return [Mash]
the options normalized as a Mash
@api private
# File lib/dm-core/adapters.rb, line 91 91: def normalize_options_uri(uri) 92: options = normalize_options_hash(uri.to_hash) 93: 94: # Extract the name/value pairs from the query portion of the 95: # connection uri, and set them as options directly. 96: if options.fetch(:query) 97: options.update(uri.query_values) 98: end 99: 100: options[:adapter] = options.fetch(:scheme) 101: 102: options 103: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.