Class: ExpressAdmin::Commandable

Inherits:
Object
  • Object
show all
Defined in:
lib/express_admin/commandable.rb

Instance Method Summary collapse

Constructor Details

#initialize(defaults = {}) ⇒ Commandable

Returns a new instance of Commandable.



3
4
5
# File 'lib/express_admin/commandable.rb', line 3

def initialize(defaults = {})
  @defaults = defaults
end

Instance Method Details

#call(mapper, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/express_admin/commandable.rb', line 7

def call(mapper, options = {})
  options = @defaults.merge(options)
  controller_name = mapper.send(:parent_resource).controller
  resource_class = "#{controller_name.classify.pluralize}Controller".constantize.resource_class
  resource_class.commands.each do |action|
    # post :foo, to: "module/controller#foo"
    mapper.member do
      mapper.post action, to: "#{controller_name}##{action}"
    end
  end
end