Class: WcoEmail::EmailFilter
- Inherits:
-
Object
- Object
- WcoEmail::EmailFilter
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/wco_email/email_filter.rb
Constant Summary collapse
- PAGE_PARAM_NAME =
:filters_page- STATUS_ACTIVE =
'active'- STATUS_INACTIVE =
'inactive'- KIND_AUTORESPOND_TMPL =
Deprecated.
2026-04-02
'autorespond-template'- KIND_AUTORESPOND_EACT =
'autorespond-email-action'- KIND_REMOVE_TAG =
'remove-tag'- KIND_ADD_TAG =
'add-tag'- KIND_DESTROY_SCHS =
'destroy-schs'- KIND_OAT =
'office-action'- KIND_AUTORESPOND =
Deprecated.
'autorespond'- KIND_DELETE =
@deprecated, DO NOT USE!
'delete'- KIND_SKIP_INBOX =
@deprecated, use add-tag
'skip-inbox'- KINDS =
@deprecated, use remove-tag
[ nil, KIND_OAT, KIND_AUTORESPOND_TMPL, KIND_AUTORESPOND_EACT, KIND_ADD_TAG, KIND_REMOVE_TAG, KIND_DESTROY_SCHS ]
Class Method Summary collapse
Instance Method Summary collapse
-
#conditions ⇒ Object
‘and’ - all conditions must match, for filter to match.
-
#conversations ⇒ Object
@TODO: change to has_and_belongs_to_many, test-driven.
-
#from_regex ⇒ Object
@deprecated, use email_filter_conditions.
-
#kind ⇒ Object
@deprecated, use filter.action.aject.kind 2026-04-02.
-
#office_action_template ⇒ Object
no habtm please has_and_belongs_to_many :action_tmpls, class_name: ‘::Wco::OfficeActionTemplate’.
-
#office_email_filters ⇒ Object
‘wco_email_email_filters’.
-
#skip_conditions ⇒ Object
‘and’ - all conditions must match, for filter to match.
- #to_s ⇒ Object
- #to_s_full ⇒ Object
- #to_xml ⇒ Object
-
#validate_actions ⇒ Object
validate :validate_actions.
-
#validate_conditions ⇒ Object
validate :validate_conditions.
Class Method Details
.active ⇒ Object
27 |
# File 'app/models/wco_email/email_filter.rb', line 27 def self.active; where( :status.in => [ nil, STATUS_ACTIVE ] ); end |
Instance Method Details
#conditions ⇒ Object
‘and’ - all conditions must match, for filter to match
39 |
# File 'app/models/wco_email/email_filter.rb', line 39 has_many :conditions, class_name: '::WcoEmail::EmailFilterCondition', inverse_of: :email_filter |
#conversations ⇒ Object
@TODO: change to has_and_belongs_to_many, test-driven.
81 |
# File 'app/models/wco_email/email_filter.rb', line 81 has_many :conversations, class_name: '::WcoEmail::Conversation', inverse_of: :filter |
#from_regex ⇒ Object
@deprecated, use email_filter_conditions
13 |
# File 'app/models/wco_email/email_filter.rb', line 13 field :from_regex |
#kind ⇒ Object
@deprecated, use filter.action.aject.kind 2026-04-02
69 |
# File 'app/models/wco_email/email_filter.rb', line 69 field :kind |
#office_action_template ⇒ Object
no habtm please has_and_belongs_to_many :action_tmpls, class_name: ‘::Wco::OfficeActionTemplate’
77 |
# File 'app/models/wco_email/email_filter.rb', line 77 belongs_to :office_action_template, class_name: '::Wco::OfficeActionTemplate', optional: true |
#office_email_filters ⇒ Object
‘wco_email_email_filters’
6 |
# File 'app/models/wco_email/email_filter.rb', line 6 store_in collection: 'office_email_filters' |
#skip_conditions ⇒ Object
‘and’ - all conditions must match, for filter to match
43 |
# File 'app/models/wco_email/email_filter.rb', line 43 has_many :skip_conditions, class_name: '::WcoEmail::EmailFilterCondition', inverse_of: :email_skip_filter |
#to_s ⇒ Object
83 84 85 |
# File 'app/models/wco_email/email_filter.rb', line 83 def to_s "EmailFilter: #{from_regex} #{from_exact} #{conditions.map { |c| c.to_s }.join }" end |
#to_s_full ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/wco_email/email_filter.rb', line 86 def to_s_full # inn = "" # inn = "#{inn}#{conditions.map { |c| c.to_s_full }.join }" if conditions.present? # inn = "#{inn}#{skip_conditions.map { |c| c.to_s_full }.join }" if skip_conditions.present? out =<<-AOL <EmailFilter > #{conditions.map { |c| c.to_s_full( indent: 2) }.join } #{skip_conditions.map { |c| c.to_s_full( indent: 2) }.join } #{actions.map { |c| c.to_s_full( indent: 2) }.join } </EmailFilter> AOL while out.match(/\n\n/) do out = out.gsub(/\n\n/, "\n") end out end |
#to_xml ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/wco_email/email_filter.rb', line 103 def to_xml attrs = '' children = '' if from_regex || from_exact attrs = "#{attrs} from=#{from_regex}#{from_exact}" end if conditions.present? children = "#{children}#{conditions.map { |c| c.to_s }.join('') }" end return "<EF #{attrs}>#{children}</EF>\n" end |
#validate_actions ⇒ Object
validate :validate_actions
32 33 34 35 36 |
# File 'app/models/wco_email/email_filter.rb', line 32 def validate_actions if actions.length == 0 errors.add(:actions, 'must be present') end end |
#validate_conditions ⇒ Object
validate :validate_conditions
47 48 49 50 51 |
# File 'app/models/wco_email/email_filter.rb', line 47 def validate_conditions if conditions.length + skip_conditions.length == 0 errors.add(:conditions, 'Either conditions or skip conditions must be present.') end end |