Module: CustomEmails::Models
- Defined in:
- lib/custom_emails/models.rb
Instance Method Summary collapse
Instance Method Details
#has_custom_emails(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/custom_emails/models.rb', line 3 def has_custom_emails(={}) = .reverse_merge({ as: :emails }) has_many [:as], as: :emailable, class_name: ::CustomEmails::Email, dependent: :destroy class_eval "def #{[:as]}_by_kind(locale=nil) assoc = #{[:as]}.includes(:kind) assoc = assoc.where(locale: locale) if locale assoc.group_by(&:kind) end" end |
#has_custom_short_messages(options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/custom_emails/models.rb', line 17 def (={}) = .reverse_merge({ as: :short_messages }) has_many [:as], as: :messageable, class_name: ::CustomEmails::ShortMessage, dependent: :destroy class_eval "def #{[:as]}_by_kind(locale=nil) assoc = #{[:as]}.includes(:kind) assoc = assoc.where(locale: locale) if locale assoc.group_by(&:kind) end" end |