diff options
author | azul <azul@riseup.net> | 2013-01-03 01:47:50 -0800 |
---|---|---|
committer | azul <azul@riseup.net> | 2013-01-03 01:47:50 -0800 |
commit | 38c87ba6eb30d8345c9c59b4f9b0d84955543ba0 (patch) | |
tree | dfb83541c077ac3deaf85c79823f8b968269534f /core/lib/extensions | |
parent | fd62997599f327c0153e23c9f8d2b074a83b43a7 (diff) | |
parent | 5732c2fa48cf4af9af122ca5366f9ffffe5f22fb (diff) |
Merge pull request #9 from leapcode/feature/read-design-from-js-files
moving the js for view definitions into separate files
Diffstat (limited to 'core/lib/extensions')
-rw-r--r-- | core/lib/extensions/couchrest.rb | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/core/lib/extensions/couchrest.rb b/core/lib/extensions/couchrest.rb index a8da23b..5938df4 100644 --- a/core/lib/extensions/couchrest.rb +++ b/core/lib/extensions/couchrest.rb @@ -1,8 +1,23 @@ -class CouchRest::Model::Designs::View - - # so we can called Ticket.method.descending or Ticket.method.ascending - def ascending - self - end +module CouchRest::Model::Designs + + class View + + # so we can called Ticket.method.descending or Ticket.method.ascending + def ascending + self + end + end + + class DesignMapper + def load_views(dir) + Dir.glob("#{dir}/*.js") do |js| + name = File.basename(js, '.js') + file = File.open(js, 'r') + view name.to_sym, + :map => file.read, + :reduce => "function(key, values, rereduce) { return sum(values); }" + end + end + end end |