mirror of
https://github.com/we-promise/sure.git
synced 2026-04-16 18:44:13 +00:00
* Move provider config to family * Update schema.rb * Add provier generator * Add table creation also * FIX generator namespace * Add support for global providers also * Remove over-engineered stuff * FIX parser * FIX linter * Some generator fixes * Update generator with fixes * Update item_model.rb.tt * Add missing linkable concern * Add missing routes * Update adapter.rb.tt * Update connectable_concern.rb.tt * Update unlinking_concern.rb.tt * Update family_generator.rb * Update family_generator.rb * Delete .claude/settings.local.json Signed-off-by: soky srm <sokysrm@gmail.com> * Move docs under API related folder * Rename Rails generator doc * Light edits to LLM generated doc * Small Lunch Flow config panel regressions. --------- Signed-off-by: soky srm <sokysrm@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
module Family::<%= class_name %>Connectable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :<%= file_name %>_items, dependent: :destroy
|
|
end
|
|
|
|
def can_connect_<%= file_name %>?
|
|
# Families can configure their own <%= class_name %> credentials
|
|
true
|
|
end
|
|
|
|
<%
|
|
# Build method parameters: required params (secrets) come first, then optional params
|
|
required_params = parsed_fields.select { |f| f[:secret] }.map { |f| "#{f[:name]}:" }
|
|
optional_params = parsed_fields.reject { |f| f[:secret] }.map { |f| "#{f[:name]}: nil" }
|
|
all_params = (required_params + optional_params + ["item_name: nil"]).join(", ")
|
|
-%>
|
|
def create_<%= file_name %>_item!(<%= all_params %>)
|
|
<%= file_name %>_item = <%= file_name %>_items.create!(
|
|
name: item_name || "<%= class_name.titleize %> Connection"<%= parsed_fields.map { |f| ",\n #{f[:name]}: #{f[:name]}" }.join("") %>
|
|
)
|
|
|
|
<%= file_name %>_item.sync_later
|
|
|
|
<%= file_name %>_item
|
|
end
|
|
|
|
def has_<%= file_name %>_credentials?
|
|
<% primary_secret = parsed_fields.find { |f| f[:secret] }&.dig(:name) -%>
|
|
<% if primary_secret -%>
|
|
<%= file_name %>_items.where.not(<%= primary_secret %>: nil).exists?
|
|
<% else -%>
|
|
<%= file_name %>_items.exists?
|
|
<% end -%>
|
|
end
|
|
end
|