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
13 14 15 |
# File 'lib/rails_sequel/rails_sequel.rb', line 13 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 |
# File 'lib/rails_sequel/rails_sequel.rb', line 4 def self.connect 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
23 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 |
# File 'lib/rails_sequel/rails_sequel.rb', line 23 def self. = {} # Use SQLite by default [:adapter] = config[:adapter] || "sqlite" # 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
18 19 20 |
# File 'lib/rails_sequel/rails_sequel.rb', line 18 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 |