Ruby:MongoDB 和存储的 js 函数(不是存储过程!)

发布于 2024-11-25 14:14:00 字数 1707 浏览 1 评论 0原文

我正在编写一个网站,它将显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文