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 ⇒ ItemEnumerator

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

Returns:



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

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

#first ⇒ BasicResource

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:



60
61
62
# File 'lib/crm/core/mixins/searchable.rb', line 60

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

#search_configurator ⇒ SearchConfigurator

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

Returns:



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

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:



38
39
40
# File 'lib/crm/core/mixins/searchable.rb', line 38

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:



49
50
51
# File 'lib/crm/core/mixins/searchable.rb', line 49

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