Class: SesDashboard::Project
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SesDashboard::Project
- Defined in:
- app/models/ses_dashboard/project.rb
Instance Method Summary collapse
-
#effective_webhook_forwards ⇒ Object
Returns the effective forwards: project-level if configured, else global config.
-
#webhook_forwards ⇒ Object
Manual JSON serialization for the webhook_forwards column.
- #webhook_forwards=(value) ⇒ Object
-
#webhook_forwards_text ⇒ Object
Virtual accessor for editing webhook_forwards as a JSON string in forms.
- #webhook_forwards_text=(value) ⇒ Object
Instance Method Details
#effective_webhook_forwards ⇒ Object
Returns the effective forwards: project-level if configured, else global config.
51 52 53 54 55 56 |
# File 'app/models/ses_dashboard/project.rb', line 51 def effective_webhook_forwards project_level = Array(webhook_forwards).select { |f| (f[:url] || f["url"]).present? } return project_level if project_level.any? Array(SesDashboard.configuration&.webhook_forwards) end |
#webhook_forwards ⇒ Object
Manual JSON serialization for the webhook_forwards column. Avoids Rails serialize API which changed between 7.0 (positional) and 8.0 (keyword-only coder:).
18 19 20 21 22 23 24 25 26 |
# File 'app/models/ses_dashboard/project.rb', line 18 def webhook_forwards raw = read_attribute(:webhook_forwards) return [] if raw.blank? return raw if raw.is_a?(Array) JSON.parse(raw) rescue JSON::ParserError [] end |
#webhook_forwards=(value) ⇒ Object
28 29 30 |
# File 'app/models/ses_dashboard/project.rb', line 28 def webhook_forwards=(value) write_attribute(:webhook_forwards, value.is_a?(String) ? value : Array(value).to_json) end |
#webhook_forwards_text ⇒ Object
Virtual accessor for editing webhook_forwards as a JSON string in forms.
33 34 35 36 |
# File 'app/models/ses_dashboard/project.rb', line 33 def webhook_forwards_text forwards = Array(webhook_forwards) forwards.empty? ? "" : JSON.pretty_generate(forwards) end |
#webhook_forwards_text=(value) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/ses_dashboard/project.rb', line 38 def webhook_forwards_text=(value) if value.blank? self.webhook_forwards = [] return end parsed = JSON.parse(value) self.webhook_forwards = Array(parsed) rescue JSON::ParserError @webhook_forwards_invalid = true end |