Class: ActiveAdmin::ResourceController::Decorators::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/resource_controller/decorators.rb

Class Method Summary collapse

Class Method Details

.draper_collection_decoratorObject



95
96
97
# File 'lib/active_admin/resource_controller/decorators.rb', line 95

def self.draper_collection_decorator
  ::Draper::CollectionDecorator
end

.draper_collection_decorator?(decorator) ⇒ Boolean

Returns:



89
90
91
92
93
# File 'lib/active_admin/resource_controller/decorators.rb', line 89

def self.draper_collection_decorator?(decorator)
  decorator && decorator <= draper_collection_decorator
rescue NameError
  false
end

.find_collection_decorator(decorator) ⇒ Object

Draper::CollectionDecorator was introduced in 1.0.0 Draper::Decorator#collection_decorator_class was introduced in 1.3.0



79
80
81
82
83
84
85
86
87
# File 'lib/active_admin/resource_controller/decorators.rb', line 79

def self.find_collection_decorator(decorator)
  if Dependency.draper?    '>= 1.3.0'
    decorator.collection_decorator_class
  elsif Dependency.draper? '>= 1.0.0'
    draper_collection_decorator
  else
    decorator
  end
end

.wrap(decorator) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/active_admin/resource_controller/decorators.rb', line 54

def self.wrap(decorator)
  collection_decorator = find_collection_decorator(decorator)

  if draper_collection_decorator? collection_decorator
    name = "#{collection_decorator.name} of #{decorator} + ActiveAdmin"
    @cache[name] ||= wrap! collection_decorator, name
  else
    collection_decorator
  end
end

.wrap!(parent, name) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/active_admin/resource_controller/decorators.rb', line 67

def self.wrap!(parent, name)
  ::Class.new parent do
    delegate :reorder, :page, :current_page, :total_pages, :limit_value,
             :total_count, :total_pages, :to_key, :group_values, :except,
             :find_each, :ransack

    define_singleton_method(:name) { name }
  end
end