如何编写Devise扩展(使用自定义数据存储) [英] How to write a Devise extension (to use a custom datastore)

查看:130
本文介绍了如何编写Devise扩展(使用自定义数据存储)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Devise写一个扩展名,允许您使用 parse_resource 作为数据存储区(而不是ActiveRecord)。 parse_resource是Parse.com的REST api的Ruby包装器。它的界面与ActiveRecord几乎相同,并且是ActiveModel的投诉。正因为如此,Devise的扩展可能不需要太多的非样板。

I'd like to write an extension for Devise that allows you to use parse_resource as the datastore (as opposed to ActiveRecord). parse_resource is a Ruby wrapper for Parse.com's REST api. It's interface is pretty much the same as ActiveRecord's and is ActiveModel complaint. Because of this, it seems possible that an extension for Devise may not require too much non-boilerplate.

但是,我找不到任何教程。所有我必须依赖的是其他扩展的来源。从 MongoMapper扩展程序,我收集到有两个主要部分:

However, I can't find any tutorials. All I have to rely on are the sources for other extensions. From the MongoMapper extension, I gather that there are two main parts:


  1. 发生器(不太需要)

这里覆盖 DeviseGenerator#(generate_model | inject_devise_content | replace_default_devise_orm )方法。

勇气(非常需要)

我不是确定这里发生了什么。似乎有很多样板,有一点自定义类型转换,底部有一个声明,我们将使用这个扩展名,而不是默认的ORM。

I'm not quite as sure what's going on here. It seems that there's a lot of boilerplate, with a little bit of custom type-casting, and at the bottom there's a declaration that we'll be using this extension instead of the default ORM.

这一切都是吗?我失踪了什么有人可以更详细地说明胆量中发生的情况吗?

Is that all there is to it? What am I missing? Can someone explain what happens in "the guts" in a bit more detail?

有没有任何简单的lint测试运行,以确保与Devise完全兼容?

Are there any simple lint tests to run to ensure full compatibility with Devise?

推荐答案

我认为最好的方法是写一个 orm_adapter 适配器。这是设计与各种场合整合的真正胆量。

I think the best approach would be to write an orm_adapter adapter for parse resource. It is the real "guts" of devise's integration with various orms.

其实很简单,包括测试套件,您可以使用。考虑到parse_resource是activemodel兼容的,适配器应该像克隆现有适配器一样简单

It is actually very straightforward and includes a test suite you can use. Considering parse_resource is activemodel compliant, the adapter should be as easy as cloning an existing adapter.

接下来,你将需要挂载orm_adapter来设计,这只是克隆其中一个文件

Next you will need to hook in the orm_adapter to devise, which is just a clone of one of these files.

这篇关于如何编写Devise扩展(使用自定义数据存储)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆