Sha256: 69fabd67b33609d5d2695ded06655129672a97422f6aa692825c53c09b6df6ac

Contents?: true

Size: 601 Bytes

Versions: 188

Compression:

Stored size: 601 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  class Javascript
    # Constant for the file that defines all the js functions.
    FUNCTIONS = File.join(File.dirname(__FILE__), "javascript", "functions.yml")

    # Load the javascript functions and define a class method for each one,
    # that memoizes the value.
    #
    # @example Get the function.
    #   Mongoid::Javascript.aggregate
    YAML.load(File.read(FUNCTIONS)).each_pair do |key, function|
      (class << self; self; end).class_eval <<-EOT
        def #{key}
          @#{key} ||= "#{function}"
        end
      EOT
    end
  end
end

Version data entries

188 entries across 96 versions & 4 rubygems

Version Path
mongoid-2.1.7 lib/mongoid/javascript.rb
mongoid-2.1.6 lib/mongoid/javascript.rb
mongoid-2.1.5 lib/mongoid/javascript.rb
mongoid-2.1.4 lib/mongoid/javascript.rb
mongoid-2.1.3 lib/mongoid/javascript.rb
mongoid-2.1.2 lib/mongoid/javascript.rb
mongoid-2.1.1 lib/mongoid/javascript.rb
mongoid-2.1.0 lib/mongoid/javascript.rb