Fixing issues when loading with rails
This commit is contained in:
parent
85109b4b22
commit
814e38f75f
9 changed files with 50 additions and 64 deletions
|
@ -4,8 +4,8 @@ module CouchRest
|
|||
|
||||
extend ActiveModel::Naming
|
||||
|
||||
include CouchRest::Model::Connection
|
||||
include CouchRest::Model::Configuration
|
||||
include CouchRest::Model::Connection
|
||||
include CouchRest::Model::Persistence
|
||||
include CouchRest::Model::Callbacks
|
||||
include CouchRest::Model::DocumentQueries
|
||||
|
|
|
@ -20,20 +20,13 @@ module CouchRest
|
|||
config.mass_assign_any_attribute = false
|
||||
config.auto_update_design_doc = true
|
||||
|
||||
config.environment = defined?(Rails) ? Rails.env : :development
|
||||
|
||||
config.connection_config_file =
|
||||
File.join(
|
||||
defined?(Rails) ? Rails.root : Dir.pwd,
|
||||
'config', 'couchdb.yml'
|
||||
)
|
||||
|
||||
app_name = defined?(Rails) ? Rails.application.class.to_s.underscore.gsub(/\/.*/, '') : 'couchrest'
|
||||
config.environment = :development
|
||||
config.connection_config_file = File.join(Dir.pwd, 'config', 'couchdb.yml')
|
||||
config.connection = {
|
||||
:protocol => 'http',
|
||||
:host => 'localhost',
|
||||
:port => '5984',
|
||||
:prefix => app_name,
|
||||
:prefix => 'couchrest',
|
||||
:suffix => nil,
|
||||
:join => '_',
|
||||
:username => nil,
|
||||
|
|
|
@ -47,20 +47,22 @@ module CouchRest
|
|||
def connection_configuration
|
||||
@connection_configuration ||=
|
||||
self.connection.update(
|
||||
(load_connection_config_file[environment] || {}).symbolize_keys
|
||||
(load_connection_config_file[environment.to_sym] || {}).symbolize_keys
|
||||
)
|
||||
end
|
||||
|
||||
def load_connection_config_file
|
||||
connection_config_cache[connection_config_file] ||=
|
||||
(File.exists?(connection_config_file) ?
|
||||
YAML::load(ERB.new(IO.read(connection_config_file)).result) :
|
||||
file = connection_config_file
|
||||
connection_config_cache[file] ||=
|
||||
(File.exists?(file) ?
|
||||
YAML::load(ERB.new(IO.read(file)).result) :
|
||||
{ }).symbolize_keys
|
||||
end
|
||||
|
||||
def connection_config_cache
|
||||
Thread.current[:connection_config_cache] ||= {}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
require "rails"
|
||||
require "active_model/railtie"
|
||||
|
||||
module CouchrestModel
|
||||
module CouchRest
|
||||
# = Active Record Railtie
|
||||
class Railtie < Rails::Railtie
|
||||
class ModelRailtie < Rails::Railtie
|
||||
config.generators.orm :couchrest_model
|
||||
config.generators.test_framework :test_unit, :fixture => false
|
||||
|
||||
initializer "couchrest_model.configure_default_connection" do
|
||||
CouchRest::Model::Base.configure do |conf|
|
||||
conf.environment = Rails.env
|
||||
conf.connection_config_file = File.join(Rails.root, 'config', 'couchdb.yml')
|
||||
conf.connection[:prefix] =
|
||||
Rails.application.class.to_s.underscore.gsub(/\/.*/, '')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue