Sha256: a28b4852ef1c61ca80b0ae39a639e0c4da149daaeb989f5a6c1b3aec50533bf3

Contents?: true

Size: 625 Bytes

Versions: 1

Compression:

Stored size: 625 Bytes

Contents

module Recliner
  class ViewFunction
    class_inheritable_accessor :definition
    
    def initialize(body)
      if body =~ /^\s*function/
        @body = body
      else
        @body = "#{definition} { #{body} }"
      end
    end
    
    def to_s
      @body
    end
    
    def ==(other)
      to_s == other.to_s
    end
  end
  
  class ViewFunction::Map < ViewFunction
    self.definition = 'function(doc)'
  end
    
  class ViewFunction::Reduce < ViewFunction
    self.definition = 'function(keys, values, rereduce)'
  end
end

Recliner::Conversions.register(Recliner::ViewFunction, :couch) { |func| func.to_s }

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recliner-0.0.1 lib/recliner/views/function.rb