auto_actions(*args)
click to toggle source
def auto_actions(*args)
options = args.extract_options!
@auto_actions = args.map do |arg|
case arg
when :all then available_auto_actions
when :write_only then available_auto_write_actions
when :read_only then available_auto_read_actions
when :lifecycle then available_auto_lifecycle_actions
else arg
end
end.flatten.uniq
except = Array(options[:except])
except_actions = except.map do |arg|
case arg
when :lifecycle then available_auto_lifecycle_actions
else arg
end
end.flatten.uniq
@auto_actions -= except_actions
def_auto_actions
end
auto_actions_for(owner, actions)
click to toggle source
def auto_actions_for(owner, actions)
name = model.reflections[owner.to_s].macro == :has_many ? owner.to_s.singularize : owner
owner_actions[owner] ||= []
Array(actions).each do |action|
case action
when :new
define_method("new_for_#{name}") { hobo_new_for owner }
when :index
define_method("index_for_#{name}") { hobo_index_for owner }
when :create
define_method("create_for_#{name}") { hobo_create_for owner }
else
raise ArgumentError, "Invalid owner action: #{action}"
end
owner_actions[owner] << action
end
end
autocomplete(*args, &block)
click to toggle source
def autocomplete(*args, &block)
options = args.extract_options!
name = args.first || model.name_attribute
field = options.delete(:field) || name
if block
index_action "complete_#{name}", &block
else
index_action "complete_#{name}" do
hobo_completions field, model, options
end
end
end
available_auto_actions()
click to toggle source
def available_auto_actions
(available_auto_read_actions +
available_auto_write_actions +
FORM_ACTIONS +
available_auto_lifecycle_actions).uniq
end
available_auto_lifecycle_actions()
click to toggle source
def available_auto_lifecycle_actions
if model.has_lifecycle?
(model::Lifecycle.publishable_creators.map { |c| [c.name, "do_#{c.name}"] } +
model::Lifecycle.publishable_transitions.map { |t| [t.name, "do_#{t.name}"] }).flatten.*.to_sym
else
[]
end
end
available_auto_read_actions()
click to toggle source
def available_auto_read_actions
READ_ONLY_ACTIONS
end
available_auto_write_actions()
click to toggle source
def available_auto_write_actions
if model.method_defined?("position_column")
WRITE_ONLY_ACTIONS + [:reorder]
else
WRITE_ONLY_ACTIONS
end
end
completions()
click to toggle source
def completions; hobo_completions end
create()
click to toggle source
def create; hobo_create end
creator_page_action(name, options={}, &block)
click to toggle source
def creator_page_action(name, options={}, &block)
define_method(name) do
creator_page_action name, options, &block
end
end
def_auto_action(name, &block)
click to toggle source
def def_auto_action(name, &block)
define_method name, &block if !method_defined?(name) && include_action?(name)
end
def_auto_actions()
click to toggle source
def def_auto_actions
self.class_eval do
def index; hobo_index end if include_action?(:index)
def show; hobo_show end if include_action?(:show)
def new; hobo_new end if include_action?(:new)
def create; hobo_create end if include_action?(:create)
def edit; hobo_show end if include_action?(:edit)
def update; hobo_update end if include_action?(:update)
def destroy; hobo_destroy end if include_action?(:destroy)
def completions; hobo_completions end if include_action?(:completions)
def reorder; hobo_reorder end if include_action?(:reorder)
end
def_lifecycle_actions
end
def_lifecycle_actions()
click to toggle source
def def_lifecycle_actions
if model.has_lifecycle?
model::Lifecycle.publishable_creators.each do |creator|
name = creator.name
def_auto_action name do
creator_page_action name
end
def_auto_action "do_#{name}" do
do_creator_action name
end
end
model::Lifecycle.publishable_transitions.each do |transition|
name = transition.name
def_auto_action name do
transition_page_action name
end
def_auto_action "do_#{name}" do
do_transition_action name
end
end
end
end
destroy()
click to toggle source
def destroy; hobo_destroy end
do_creator_action(name, options={}, &block)
click to toggle source
def do_creator_action(name, options={}, &block)
define_method("do_#{name}") do
do_creator_action name, options, &block
end
end
do_transition_action(name, options={}, &block)
click to toggle source
def do_transition_action(name, options={}, &block)
define_method("do_#{name}") do
do_transition_action name, options, &block
end
end
edit()
click to toggle source
include_action?(name)
click to toggle source
def include_action?(name)
name.to_sym.in?(@auto_actions)
end
index()
click to toggle source
def index; hobo_index end
index_action(*names, &block)
click to toggle source
def index_action(*names, &block)
options = names.extract_options!
index_actions.concat(names)
for name in names
if block
define_method(name, &block)
else
if scope = options.delete(:scope)
if scope.is_a?(Symbol)
define_method(name) { hobo_index model.send(scope), options.dup }
else
define_method(name) { hobo_index scope, options.dup }
end
else
define_method(name) { hobo_index options.dup }
end
end
end
end
model()
click to toggle source
def model
@model ||= controller_name.camelcase.singularize.constantize
end
model_name()
click to toggle source
def model_name
model.name.underscore
end
new()
click to toggle source
reorder()
click to toggle source
def reorder; hobo_reorder end
show()
click to toggle source
show_action(*names, &block)
click to toggle source
def show_action(*names, &block)
options = names.extract_options!
show_actions.concat(names)
for name in names
if block
define_method(name, &block)
else
define_method(name) { hobo_show options.dup }
end
end
end
transtion_page_action(name, options={}, &block)
click to toggle source
def transtion_page_action(name, options={}, &block)
define_method(name) do
transtion_page_action name, options, &block
end
end
update()
click to toggle source
def update; hobo_update end
web_method(web_name, options={}, &block)
click to toggle source
def web_method(web_name, options={}, &block)
web_methods << web_name.to_sym
method = options.delete(:method) || web_name
got_block = block_given?
define_method web_name do
opts = options.dup
self.this = find_instance(opts)
raise Hobo::PermissionDeniedError unless @this.method_callable_by?(current_user, method)
if got_block
this.with_acting_user(current_user) { instance_eval(&block) }
else
@this.send(method)
end
hobo_ajax_response unless performed?
end
end