Class: Kadmin::FinderDecorator

Inherits:
Object
  • Object
show all
Defined in:
app/decorators/kadmin/finder_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(finder) ⇒ FinderDecorator

Returns a new instance of FinderDecorator.



8
9
10
# File 'app/decorators/kadmin/finder_decorator.rb', line 8

def initialize(finder)
  @finder = finder
end

Instance Attribute Details

#finderKadmin::Finder (readonly)

Returns underlying finder model.

Returns:



4
5
6
# File 'app/decorators/kadmin/finder_decorator.rb', line 4

def finder
  @finder
end

Instance Method Details

#applied_filtersString

Returns a description of the current applied filters.

Returns:

  • (String)

    a description of the current applied filters



18
19
20
21
22
23
24
25
26
# File 'app/decorators/kadmin/finder_decorator.rb', line 18

def applied_filters
  filters = @finder.filters.reduce([]) do |acc, (name, filter)|
    next(acc) if filter.value.blank?
    acc << %(<strong>#{filter.value}</strong> on <em>#{name}</em>).html_safe
  end
  applied_filters = "(filtering: #{filters.join('; ')})" unless filters.empty?

  return applied_filters
end

#pagerKadmin::PagerDecorator

Returns decorated pager of the underlying finder.

Returns:



29
30
31
# File 'app/decorators/kadmin/finder_decorator.rb', line 29

def pager
  return @pager ||= Kadmin::PagerDecorator.new(@finder.pager)
end

#resource_nameString

Returns human readable, singular/plural form of the finder's model.

Returns:

  • (String)

    human readable, singular/plural form of the finder's model



13
14
15
# File 'app/decorators/kadmin/finder_decorator.rb', line 13

def resource_name
  return @finder.scope.model_name.human(count: pager.displayed_items)
end