Module: RailsSequel
- Defined in:
- lib/rails_sequel/version.rb,
lib/rails_sequel/rails_sequel.rb
Class Method Summary collapse
-
.config ⇒ Object
Returns loaded database.yml configuration for current environment.
-
.connect ⇒ Object
Connects to database using constructed Database Connection URI.
-
.prepare_options ⇒ Object
Constructs Database Connection URI.
-
.reset_config! ⇒ Object
Resets config.
-
.version ⇒ Object
Returns current plugin version.
Class Method Details
.config ⇒ Object
Returns loaded database.yml configuration for current environment
14 15 16 |
# File 'lib/rails_sequel/rails_sequel.rb', line 14 def self.config @config ||= YAML::load(ERB.new(IO.read(File.join(Rails.root, "config", "database.yml"))).result)[Rails.env].with_indifferent_access end |
.connect ⇒ Object
Connects to database using constructed Database Connection URI
4 5 6 7 8 9 10 11 |
# File 'lib/rails_sequel/rails_sequel.rb', line 4 def self.connect return @connection if @connection @connection = Sequel.connect( = self.) if [:adapter] == 'mysql' @connection.execute("SET SQL_AUTO_IS_NULL=0") end @connection end |
.prepare_options ⇒ Object
Constructs Database Connection URI
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rails_sequel/rails_sequel.rb', line 24 def self. = {} # Use SQLite by default [:adapter] = config[:adapter] || "sqlite" if [:adapter]=='sqlite3' [:adapter] = 'sqlite' end # Use localhost as default host [:host] = config[:host] || config[:hostname] || "localhost" # Default user is an empty string. Both username and user keys are supported. [:user] = config[:username] || config[:user] || "" [:password] = config[:password] || "" # Both encoding and charset options are supported, default is utf8 [:encoding] = config[:encoding] || config[:charset] || "utf8" # Default database is hey_dude_configure_your_database [:database] = config[:database] || "hey_dude_configure_your_database" # MSSQL support [:db_type, :socket, :charset, :encoding].each do |var| [var] = config[var] if config[var] end # JDBC support [:url, :uri].each do |var| [var] = config[var] if config[var] end [:loggers] = [Rails.logger] end |
.reset_config! ⇒ Object
Resets config
19 20 21 |
# File 'lib/rails_sequel/rails_sequel.rb', line 19 def self.reset_config! @config = nil end |
.version ⇒ Object
Returns current plugin version
3 4 5 6 7 |
# File 'lib/rails_sequel/version.rb', line 3 def self.version return @version if @version config = YAML.load(File.read(File.join(File.dirname(__FILE__), '../../VERSION.yml'))) @version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}" end |