summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-11-21 09:59:20 -0800
committerjessib <jessib@riseup.net>2013-11-21 09:59:20 -0800
commit2d9100ef03d283d91b2b8be38fc11ee3c2024a84 (patch)
tree93ad87436604a6a63cdd13c60aa042727023990f
parentd2eaffde87286c0cc9c0658503a60706759f7f51 (diff)
parentcf68a79639861e69f61af85b43a3f72ed7763439 (diff)
Merge pull request #115 from azul/feature/dump-design-docs
Enable dumping design docs to files
-rw-r--r--core/lib/extensions/couchrest.rb35
-rw-r--r--core/lib/tasks/leap_web_core_tasks.rake13
2 files changed, 35 insertions, 13 deletions
diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb
index 91dfc1c..84cfbb3 100644
--- a/core/lib/extensions/couchrest.rb
+++ b/core/lib/extensions/couchrest.rb
@@ -47,28 +47,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..734fae9 100644
--- a/core/lib/tasks/leap_web_core_tasks.rake
+++ b/core/lib/tasks/leap_web_core_tasks.rake
@@ -1,4 +1,9 @@
-# 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
+