summaryrefslogtreecommitdiff
path: root/core/lib
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
committerjessib <jessib@riseup.net>2013-12-17 12:02:07 -0800
commit98a247acb4d1be484c2982d48ec038eed3de3d55 (patch)
treef176092fa43145b9d8ce00a180fab70cf62da456 /core/lib
parent634db9875cc8f6f6b9a4a83dfc6b8d53728eb2b5 (diff)
parent83cd3d95b78b6df9ac33a8ee169e570f4d3e2eeb (diff)
Merge branch 'develop' into feature/billing-no-authenticated-payments
Conflicts: billing/config/locales/en.yml
Diffstat (limited to 'core/lib')
-rw-r--r--core/lib/extensions/couchrest.rb45
-rw-r--r--core/lib/tasks/leap_web_core_tasks.rake29
2 files changed, 55 insertions, 19 deletions
diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb
index 91dfc1c..a9a195e 100644
--- a/core/lib/extensions/couchrest.rb
+++ b/core/lib/extensions/couchrest.rb
@@ -23,20 +23,18 @@ module CouchRest
end
end
- module Errors
- class ConnectionFailed < CouchRestModelError; end
- end
-
module Connection
module ClassMethods
def use_database(db)
@database = prepare_database(db)
- rescue RestClient::Unauthorized,
+ rescue RestClient::Exception,
Errno::EHOSTUNREACH,
Errno::ECONNREFUSED => e
- raise CouchRest::Model::Errors::ConnectionFailed.new(e.to_s)
+ message = "Could not connect to couch database #{db} due to #{e.to_s}"
+ Rails.logger.warn message
+ raise e.class.new(message) if APP_CONFIG[:reraise_errors]
end
end
@@ -47,28 +45,45 @@ module CouchRest
def self.load_all_models_with_engines
self.load_all_models_without_engines
return unless defined?(Rails)
- Dir[Rails.root + 'app/models/**/*.rb'].each do |path|
- require path
- end
Dir[Rails.root + '*/app/models/**/*.rb'].each do |path|
require path
end
end
- def self.all_models_and_proxies
- callbacks = migrate_each_model(find_models)
- callbacks += migrate_each_proxying_model(find_proxying_models)
- cleanup(callbacks)
+ class << self
+ alias_method_chain :load_all_models, :engines
+ end
+
+ def dump_all_models
+ prepare_directory
+ find_models.each do |model|
+ model.design_docs.each do |design|
+ dump_design(model, design)
+ end
+ end
end
+ protected
+ def dump_design(model, design)
+ dir = prepare_directory model.name.tableize
+ filename = design.id.sub('_design/','') + '.json'
+ puts dir + filename
+ design.checksum
+ File.open(dir + filename, "w") do |file|
+ file.write(JSON.pretty_generate(design.to_hash))
+ end
+ end
- class << self
- alias_method_chain :load_all_models, :engines
+ def prepare_directory(dir = '')
+ dir = Rails.root + 'tmp' + 'designs' + dir
+ Dir.mkdir(dir) unless Dir.exists?(dir)
+ return dir
end
end
end
+
end
class ModelRailtie
diff --git a/core/lib/tasks/leap_web_core_tasks.rake b/core/lib/tasks/leap_web_core_tasks.rake
index ae5b79b..ec6abac 100644
--- a/core/lib/tasks/leap_web_core_tasks.rake
+++ b/core/lib/tasks/leap_web_core_tasks.rake
@@ -1,4 +1,25 @@
-# desc "Explaining what the task does"
-# task :leap_web_core do
-# # Task goes here
-# end
+namespace :couchrest do
+
+ desc "Dump all the design docs found in each model"
+ task :dump => :environment do
+ CouchRest::Model::Utils::Migrate.load_all_models
+ CouchRest::Model::Utils::Migrate.dump_all_models
+ end
+end
+
+namespace :cleanup do
+
+ desc "Cleanup all expired session documents"
+ task :sessions => :environment do
+ # make sure this is the same as in
+ # config/initializers/session_store.rb
+ store = CouchRest::Session::Store.new expire_after: 1800
+ store.cleanup(store.expired)
+ end
+
+ desc "Cleanup all expired tokens"
+ task :tokens => :environment do
+ Token.destroy_all_expired
+ end
+end
+