Module: Care::AutoFinder::Findable::ClassMethods

Defined in:
lib/care/auto_finder/findable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chain_filterObject

Returns the value of attribute chain_filter.



8
9
10
# File 'lib/care/auto_finder/findable.rb', line 8

def chain_filter
  @chain_filter
end

Instance Method Details

#call(options = {}) ⇒ Object

Examples:

FooBarFinder
  .call(
    relation: FooBar,
    params: { page: 10, limit: 2, name: 'Lorem' }
  )

Parameters:

  • options (Hash) (defaults to: {})

    параметры для работы файдера

Options Hash (options):

  • :relation (ActiveRecord)

    модель, для которой будет вестись поиск

  • :params (Hash)

    опции для поиска



39
40
41
# File 'lib/care/auto_finder/findable.rb', line 39

def call(options = {})
  new(options).call
end

#entityObject



15
16
17
# File 'lib/care/auto_finder/findable.rb', line 15

def entity
  self.relation = yield
end

#filter_by(*filters) ⇒ Object



19
20
21
# File 'lib/care/auto_finder/findable.rb', line 19

def filter_by(*filters)
  self.chain_filter = filters
end

#relationObject



23
24
25
# File 'lib/care/auto_finder/findable.rb', line 23

def relation
  @relation ||= /(.*)Finder/.match(name)[1].singularize.constantize
end

#set_relation(relation) ⇒ Object

attr_accessor :relation



11
12
13
# File 'lib/care/auto_finder/findable.rb', line 11

def set_relation(relation)
  @relation = relation
end