Module: MessageTrain::ClassMethods

Defined in:
lib/message_train/class_methods.rb

Overview

Extended when message_train mixin is run

Instance Method Summary collapse

Instance Method Details

#collective?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/message_train/class_methods.rb', line 47

def collective?
  valid_senders_method != :self_collection
end

#find_by_message_train_slug(slug) ⇒ Object



16
17
18
# File 'lib/message_train/class_methods.rb', line 16

def find_by_message_train_slug(slug)
  find_by(slug_column => slug.strip)
end

#message_train_address_book(for_participant) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/message_train/class_methods.rb', line 4

def message_train_address_book(for_participant)
  method = MessageTrain.configuration.address_book_methods[
    message_train_table_sym
  ]
  method ||= MessageTrain.configuration.address_book_method
  if method.present? && respond_to?(method)
    send(method, for_participant)
  else
    all
  end
end

#name_columnObject



31
32
33
# File 'lib/message_train/class_methods.rb', line 31

def name_column
  MessageTrain.configuration.name_columns[message_train_table_sym] || :name
end

#slug_columnObject



27
28
29
# File 'lib/message_train/class_methods.rb', line 27

def slug_column
  MessageTrain.configuration.slug_columns[message_train_table_sym] || :slug
end

#valid_recipients_methodObject



41
42
43
44
45
# File 'lib/message_train/class_methods.rb', line 41

def valid_recipients_method
  MessageTrain.configuration
              .valid_recipients_methods[message_train_table_sym] ||
    :self_collection
end

#valid_senders_methodObject



35
36
37
38
39
# File 'lib/message_train/class_methods.rb', line 35

def valid_senders_method
  MessageTrain.configuration
              .valid_senders_methods[message_train_table_sym] ||
    :self_collection
end

#where_slug_starts_with(string) ⇒ Object



20
21
22
23
24
25
# File 'lib/message_train/class_methods.rb', line 20

def where_slug_starts_with(string)
  return where(nil) unless string.present?
  pattern = Regexp.union('\\', '%', '_')
  string = string.gsub(pattern) { |x| ['\\', x].join }
  where("#{slug_column} LIKE ?", "#{string}%")
end