lib/active_admin/dsl.rb in yousty-activeadmin-1.0.4.pre vs lib/active_admin/dsl.rb in yousty-activeadmin-1.0.5.pre
- old
+ new
@@ -1,24 +1,23 @@
module ActiveAdmin
- #
# The Active Admin DSL. This class is where all the registration blocks
- # are instance eval'd. This is the central place for the API given to
- # users of Active Admin
+ # are evaluated. This is the central place for the API given to
+ # users of Active Admin.
#
class DSL
def initialize(config)
@config = config
end
# Runs the registration block inside this object
def run_registration_block(&block)
- instance_eval &block if block_given?
+ instance_exec &block if block_given?
end
- # The instance of ActiveAdmin::Config that's being registered
+ # The instance of ActiveAdmin::Resource that's being registered
# currently. You can use this within your registration blocks to
# modify options:
#
# eg:
#
@@ -49,17 +48,17 @@
# include HelpSidebar
# end
#
# @param [Module] mod A module to include
#
- # @returns [Nil]
+ # @return [Nil]
def include(mod)
mod.included(self)
end
# Returns the controller for this resource. If you pass a
- # block, it will be eval'd in the controller
+ # block, it will be evaluated in the controller.
#
# Example:
#
# ActiveAdmin.register Post do
#
@@ -70,23 +69,31 @@
# end
#
# end
#
def controller(&block)
- @config.controller.class_eval(&block) if block_given?
+ @config.controller.class_exec(&block) if block_given?
@config.controller
end
# Add a new action item to the resource
#
+ # @param [Symbol] name
# @param [Hash] options valid keys include:
# :only: A single or array of controller actions to display
# this action item on.
# :except: A single or array of controller actions not to
# display this action item on.
- def action_item(options = {}, &block)
- config.add_action_item(options, &block)
+ def action_item(name = nil, options = {}, &block)
+ if name.is_a?(Hash)
+ options = name
+ name = nil
+ end
+
+ Deprecation.warn "using `action_item` without a name is deprecated! Use `action_item(:edit)`." unless name
+
+ config.add_action_item(name, options, &block)
end
# Add a new batch action item to the resource
# Provide a symbol/string to register the action, options, & block to execute on request
#
@@ -99,10 +106,10 @@
# => :confirm is a string which the user will have to accept in order to process the action
#
def batch_action(title, options = {}, &block)
# Create symbol & title information
if title.is_a? String
- sym = title.titleize.gsub(' ', '').underscore.to_sym
+ sym = title.titleize.tr(' ', '').underscore.to_sym
else
sym = title
title = sym.to_s.titleize
end