summaryrefslogtreecommitdiff
path: root/core/lib/extensions/couchrest.rb
blob: ca4b608bfbe16c4c9025fa0785c619070b1059c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module CouchRest
  module 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

  class ModelRailtie
    config.action_dispatch.rescue_responses.merge!(
      'CouchRest::Model::DocumentNotFound' => :not_found,
      'RestClient::ResourceNotFound' => :not_found
    )
  end
end