Module: MongoMapper::CustomFunctions

Defined in:
lib/mm-custom-functions.rb

Constant Summary collapse

@@load_dir =
nil

Class Method Summary collapse

Class Method Details

.clearObject

wipes all custom functions



16
17
18
# File 'lib/mm-custom-functions.rb', line 16

def self.clear
  MongoMapper.database.eval("db.system.js.remove({});")
end

.function(name) ⇒ Object

find one specific function defined in the load_dir



51
52
53
# File 'lib/mm-custom-functions.rb', line 51

def self.function(name)
  func_from_file(File.join(load_dir, "#{name}.js"))
end

.functionsObject

returns all functions in the load_dir as an array of hashes: returns array of

_id   => file name (without the extension),
value => file contents



44
45
46
47
48
# File 'lib/mm-custom-functions.rb', line 44

def self.functions
  Dir[File.join(load_dir, '*.js')].collect do |path|
    func_from_file(path)
  end
end

.load(name) ⇒ Object

updates a specific function



34
35
36
# File 'lib/mm-custom-functions.rb', line 34

def self.load(name)
  install_function(function(name))
end

.load_dirObject



7
8
9
# File 'lib/mm-custom-functions.rb', line 7

def self.load_dir
  @@load_dir
end

.load_dir=(dir) ⇒ Object



11
12
13
# File 'lib/mm-custom-functions.rb', line 11

def self.load_dir=(dir)
  @@load_dir = dir
end

.reloadObject

updates all functions in the load dir



27
28
29
30
31
# File 'lib/mm-custom-functions.rb', line 27

def self.reload
  functions.each do |func|
    install_function(func)
  end
end

.resetObject

wipes all functions and reloads



21
22
23
24
# File 'lib/mm-custom-functions.rb', line 21

def self.reset
  clear
  reload
end