Ruby:MongoDB 和存储的 js 函数(不是存储过程!)
我正在编写一个网站,它将显示 MongoDB 中的对象,想法是使其尽可能灵活。为此,我创建了一个由以下对象组成的集合 config
:
categories: {
"Title": { /// thats a displayed category title
[ collection: "collection_name", ] /// defaultize to title.snake_case
[ template: "some_template", ] /// defaultize to title.snake_case
[ css: { /// object will be passed to template
}, ]
fields: {
"Field Title": {
[name: "attribute_name" ,] /// defaultize to field_title.snake_case
[required: true or false, ] /// defaultize to false
[template: "template_name", ] /// defaultize to field_title.snake_case
[ css: { /// same as above, passed to template
// ..
}, ]
[validations: [
function(field_value, record){
return []; /// this should be array with errors or empty if none
},
["validationName", ...] /// this should be one of functions defined in validations collection name or DBRef to it
], ]
},
// ...
}
}
}
snake_case 实际上是一个 String
方法,在 ActiveSupport 中称为 underscore
:“ AsdAsd".下划线=> “asd_asd”。 这些 []
定义可选属性。
一切都很好并且按预期工作,直到我遇到验证。 这些验证存储在 MongoDB 中,并使用控制台我可以这样做:
> db.config.findOne().categories.text.exec("some_string", {...});
[ ]
>
Can i do the same from Ruby using MongoID or MongoMapper? 或者我应该改变我的方法?
谢谢。
I'm writing a site which will display objects from MongoDB, idea is to make it as flexible as possible. To do that I've created a collection config
which consists of following objects:
categories: {
"Title": { /// thats a displayed category title
[ collection: "collection_name", ] /// defaultize to title.snake_case
[ template: "some_template", ] /// defaultize to title.snake_case
[ css: { /// object will be passed to template
}, ]
fields: {
"Field Title": {
[name: "attribute_name" ,] /// defaultize to field_title.snake_case
[required: true or false, ] /// defaultize to false
[template: "template_name", ] /// defaultize to field_title.snake_case
[ css: { /// same as above, passed to template
// ..
}, ]
[validations: [
function(field_value, record){
return []; /// this should be array with errors or empty if none
},
["validationName", ...] /// this should be one of functions defined in validations collection name or DBRef to it
], ]
},
// ...
}
}
}
snake_case is actually a String
method known as underscore
in ActiveSupport: "AsdAsd".underscore => "asd_asd".
Those []
define optional attributes.
Everything was fine and worked as expected until I've ran into validations.
Those validations are stored in MongoDB and using console I can do like that:
> db.config.findOne().categories.text.exec("some_string", {...});
[ ]
>
Can i do the same from Ruby using MongoID or MongoMapper?
Or I should change my approach?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论