Class: WcoEmail::EmailFilter
- Inherits:
-
Object
- Object
- WcoEmail::EmailFilter
- Includes:
- Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/wco_email/email_filter.rb
Overview
2023-03-04 vp When I receive one.
Constant Summary collapse
- PAGE_PARAM_NAME =
:filters_page
- KIND_AUTORESPOND_TMPL =
'autorespond-template'
- KIND_AUTORESPOND_EACT =
'autorespond-email-action'
- KIND_REMOVE_TAG =
'remove-tag'
- KIND_ADD_TAG =
'add-tag'
- KIND_DESTROY_SCHS =
'destroy-schs'
- 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_AUTORESPOND_TMPL, KIND_AUTORESPOND_EACT, KIND_ADD_TAG, KIND_REMOVE_TAG, KIND_DESTROY_SCHS]
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.
-
#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.
Instance Method Details
#conditions ⇒ Object
‘and’ - all conditions must match, for filter to match
34 |
# File 'app/models/wco_email/email_filter.rb', line 34 has_many :conditions, class_name: '::WcoEmail::EmailFilterCondition', inverse_of: :email_filter |
#conversations ⇒ Object
@TODO: change to has_and_belongs_to_many, test-driven.
72 |
# File 'app/models/wco_email/email_filter.rb', line 72 has_many :conversations, class_name: '::WcoEmail::Conversation', inverse_of: :filter |
#skip_conditions ⇒ Object
‘and’ - all conditions must match, for filter to match
38 |
# File 'app/models/wco_email/email_filter.rb', line 38 has_many :skip_conditions, class_name: '::WcoEmail::EmailFilterCondition', inverse_of: :email_skip_filter |
#to_s ⇒ Object
74 75 76 |
# File 'app/models/wco_email/email_filter.rb', line 74 def to_s "EmailFilter: #{from_regex} #{from_exact} #{conditions.map { |c| c.to_s }.join }" end |
#to_s_full ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/wco_email/email_filter.rb', line 77 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 #{from_regex} #{from_exact}> #{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
94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/wco_email/email_filter.rb', line 94 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
27 28 29 30 31 |
# File 'app/models/wco_email/email_filter.rb', line 27 def validate_actions if actions.length == 0 errors.add(:actions, 'must be present') end end |
#validate_conditions ⇒ Object
validate :validate_conditions
42 43 44 45 46 |
# File 'app/models/wco_email/email_filter.rb', line 42 def validate_conditions if conditions.length + skip_conditions.length == 0 errors.add(:conditions, 'Either conditions or skip conditions must be present.') end end |