Sha256: 95dfe794ff2ce8d45a766347bf39eda3de46035856a91a7db12013daec36d754

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

module JasonDB
  def JasonDB::class_exists? class_name
    const = Module.const_get(class_name)
    return const.is_a? Class
  rescue NameError
    return false
  end

  #jason_url here doesn't include the http[s]:// part, but does include the domain and a trailing '/'
  #( so it's "rest.jasondb.com/<domain>/" )
  def JasonDB::db_auth_url mode=:secure
    #check to see if this is a Rails environment
    if class_exists? "Rails"
      config = Rails.configuration.database_configuration[Rails.env]
    else
      #if not, use some defaults for testing medea.
      config = {"user" => "michael",
                "topic" => "medea-test",
                "password" => "password"}
    end

    user = config["user"]
    topic = config["topic"]
    password = config["password"]
    if config["jason_host"]
      host = config["jason_host"]
    else
      host = "rest.jasondb.com"
    end
    protocol = "http"
    protocol << "s" if mode == :secure
    "#{protocol}://#{user}:#{password}@#{host}/#{topic}/"
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
medea-0.2.14 lib/medea/jasondb.rb