Module: Crm::Core::Mixins::Searchable::ClassMethods

Included in:
Account, Activity, Crm::Collection, Crm::Contact, Crm::Core::Mixins::Searchable, Event, EventContact, Mailing
Defined in:
lib/crm/core/mixins/searchable.rb

Instance Method Summary collapse

Instance Method Details

#all(include_deleted: false) ⇒ ItemEnumerator

Returns an enumerator for iterating over all items of this base type. The items are sorted by created_at.

Parameters:

  • include_deleted (Boolean) (defaults to: false)

    whether to include deleted items. Default: false.

Returns:



25
26
27
28
29
30
31
# File 'lib/crm/core/mixins/searchable.rb', line 25

def all(include_deleted: false)
  search_configurator.
      sort_by('created_at').
      unlimited.
      include_deleted(include_deleted).
      perform_search
end

#firstBasicResource

Returns the item of this base type that was created first.

Returns:



12
13
14
15
16
17
18
# File 'lib/crm/core/mixins/searchable.rb', line 12

def first
  search_configurator.
      sort_by('created_at').
      limit(1).
      perform_search.
      first
end

#query(query) ⇒ SearchConfigurator

Returns a new SearchConfigurator set to the given query. Additionally, it is limited to this base type and can be further refined using chainable methods. This method is equivalent to search_configurator.query(query). See SearchConfigurator#query for examples.

Returns:



62
63
64
# File 'lib/crm/core/mixins/searchable.rb', line 62

def query(query)
  search_configurator.query(query)
end

#search_configuratorSearchConfigurator

Returns a new SearchConfigurator limited to this base type. It can be further refined using chainable methods.

Returns:



70
71
72
73
74
# File 'lib/crm/core/mixins/searchable.rb', line 70

def search_configurator
  SearchConfigurator.new({
    filters: filters_for_base_type,
  })
end

#where(field, condition, value = nil) ⇒ SearchConfigurator

Returns a new SearchConfigurator set to the given filter (field, condition, value). Additionally, it is limited to this base type and can be further refined using chainable methods. This method is equivalent to search_configurator.and(field, condition, value). See SearchConfigurator#and for parameters and examples.

Returns:



40
41
42
# File 'lib/crm/core/mixins/searchable.rb', line 40

def where(field, condition, value = nil)
  search_configurator.and(field, condition, value)
end

#where_not(field, condition, value = nil) ⇒ SearchConfigurator

Returns a new SearchConfigurator set to the given negated filter (field, condition, value). Additionally, it is limited to this base type and can be further refined using chainable methods. This method is equivalent to search_configurator.and_not(field, condition, value). See SearchConfigurator#and_not for parameters and examples.

Returns:



51
52
53
# File 'lib/crm/core/mixins/searchable.rb', line 51

def where_not(field, condition, value = nil)
  search_configurator.and_not(field, condition, value)
end