Module: RailsAdmin::Config::Actions

Defined in:
lib/rails_admin/config/actions.rb,
lib/rails_admin/config/actions/new.rb,
lib/rails_admin/config/actions/show.rb,
lib/rails_admin/config/actions/edit.rb,
lib/rails_admin/config/actions/base.rb,
lib/rails_admin/config/actions/index.rb,
lib/rails_admin/config/actions/delete.rb,
lib/rails_admin/config/actions/export.rb,
lib/rails_admin/config/actions/dashboard.rb,
lib/rails_admin/config/actions/bulk_delete.rb,
lib/rails_admin/config/actions/show_in_app.rb,
lib/rails_admin/config/actions/history_show.rb,
lib/rails_admin/config/actions/history_index.rb

Defined Under Namespace

Classes: Base, BulkDelete, Dashboard, Delete, Edit, Export, HistoryIndex, HistoryShow, Index, New, Show, ShowInApp

Class Method Summary collapse

Class Method Details

.add_action(key, parent_class, parent, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/rails_admin/config/actions.rb', line 48

def add_action(key, parent_class, parent, &block)
  a = "RailsAdmin::Config::Actions::#{parent_class.to_s.camelize}".constantize.new
  a.instance_eval(%(
    #{parent} true
    def key
      :#{key}
    end
  ))
  add_action_custom_key(a, &block)
end

.all(scope = nil, bindings = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_admin/config/actions.rb', line 5

def all(scope = nil, bindings = {})
  if scope.is_a?(Hash)
    bindings = scope
    scope = :all
  end
  scope ||= :all
  init_actions!
  actions = begin
    case scope
    when :all
      @@actions
    when :root
      @@actions.select(&:root?)
    when :collection
      @@actions.select(&:collection?)
    when :bulkable
      @@actions.select(&:bulkable?)
    when :member
      @@actions.select(&:member?)
    end
  end
  actions = actions.collect { |action| action.with(bindings) }
  bindings[:controller] ? actions.select(&:visible?) : actions
end

.collection(key, parent_class = :base, &block) ⇒ Object



36
37
38
# File 'lib/rails_admin/config/actions.rb', line 36

def collection(key, parent_class = :base, &block)
  add_action key, parent_class, :collection, &block
end

.find(custom_key, bindings = {}) ⇒ Object



30
31
32
33
34
# File 'lib/rails_admin/config/actions.rb', line 30

def find(custom_key, bindings = {})
  init_actions!
  action = @@actions.detect { |a| a.custom_key == custom_key }.try(:with, bindings)
  bindings[:controller] ? (action.try(:visible?) && action || nil) : action
end

.member(key, parent_class = :base, &block) ⇒ Object



40
41
42
# File 'lib/rails_admin/config/actions.rb', line 40

def member(key, parent_class = :base, &block)
  add_action key, parent_class, :member, &block
end

.register(name, klass = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rails_admin/config/actions.rb', line 63

def register(name, klass = nil)
  if klass.nil? && name.is_a?(Class)
    klass = name
    name = klass.to_s.demodulize.underscore.to_sym
  end

  instance_eval %{
    def #{name}(&block)
      action = #{klass}.new
      add_action_custom_key(action, &block)
    end
  }
end

.resetObject



59
60
61
# File 'lib/rails_admin/config/actions.rb', line 59

def reset
  @@actions = nil
end

.root(key, parent_class = :base, &block) ⇒ Object



44
45
46
# File 'lib/rails_admin/config/actions.rb', line 44

def root(key, parent_class = :base, &block)
  add_action key, parent_class, :root, &block
end