簡體   English   中英

如何為Rails中的第三方集成建模/關聯每個用戶的配置設置?

[英]How to model/associate per-user configuration settings for third-party integrations in Rails?

我正在做一個允許用戶與第三方服務集成的項目。 每個服務將可能具有自己獨特的一組配置值。 我正在努力決定如何命名和建模將與用戶相關聯的數據。

示例數據:

  • 服務一

    • base_uri:'abc'
    • api_token:“ xyz”
  • 服務二

    • secret_key:'123'
    • favorite_color:“綠色”

我首先創建了一個諸如Integration::ServiceOne類的模型,但是由於命名空間的原因,代碼開始變得混亂。 我也不喜歡將它們稱為“ ServiceOnes”。

您將如何在Rails應用程序中命名和建模這些數據?

您可能有一個名為ConfigValues的模型:

belongs_to :user   
user_id:integer
service_id:integer
name:string
value:string # caveat here is you need to be careful with parsing different value types

然后是查詢模型, Services

has_many :service_configs
service_id:integer
service_name:string

也許還有第三個模型,例如ServiceConfig ,它描述了給定服務的可能配置值:

belongs_to :service
variable_name
service_id

然后,您可以調用諸如user.config_values.where(service_id: 1)類的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM