I have a method that's used in many places in my app, both in some controllers and other models.
class MyClass
LONG_CONSTANT_1 = "function(x) { some_long_js_function }"
LONG_CONSTANT_2 = "function(x) { another_really_long_js_function }"
def self.my_group_method(my_constant)
count = MyClass.collection.group(
:keyf => my_constant,
:reduce => "function(x, y) {y.count += x.count;}"
)
end
end
So even though the method called inside my_group_method is related to MongoDB, the question is itself not related at all, basically I want to be able to call
MyClass.my_group_method(LONG_CONSTANT_2)
or
MyClass.my_group_method(LONG_CONSTANT_1)
(there are actually several more constants needed but the example has only 2)
Unfortunately my implementation here results in the error: NameError: wrong constant name LONG_CONSTANT_1
Any ideas at how to best implement this behavior? I'm likely going to have several long constants (which are actually JS functions as strings that get sent to MongoDB), what am I getting wrong about the design pattern I'm using here?
Any help would be greatly appreciated!