Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create on_action objects when first called instead of when initialized

  • Loading branch information...
commit a82d851c3960e9a4c5c902ff0a069a0988bdd601 1 parent 25a388e
@quirkey authored
Showing with 6 additions and 13 deletions.
  1. +5 −12 lib/qadmin/configuration.rb
  2. +1 −1  test/test_qadmin_configuration.rb
View
17 lib/qadmin/configuration.rb
@@ -140,24 +140,17 @@ class Resource < Base
ACTIONS = [:index, :show, :new, :create, :edit, :update, :destroy].freeze
- hash_accessor :available_actions, :default => ACTIONS
+ hash_accessor :available_actions, :default => ACTIONS.dup
hash_accessor :ports, :default => false
hash_accessor :multipart_forms, :default => false
hash_accessor :controls, :default => []
- hash_accessor :on_index
- hash_accessor :on_show
- hash_accessor :on_new
- hash_accessor :on_create
- hash_accessor :on_edit
- hash_accessor :on_update
- hash_accessor :on_destroy
+ ACTIONS.each do |action|
+ hash_accessor "on_#{action}"
- def initialize(options = {})
- super
- ACTIONS.each do |action|
- self["on_#{action}"] = "Qadmin::Configuration::Actions::#{action.to_s.classify}".constantize.new(self.dup.merge(:base => self))
+ define_method("on_#{action}") do
+ self["on_#{action}"] ||= "Qadmin::Configuration::Actions::#{action.to_s.classify}".constantize.new(self.dup.merge(:base => self))
end
end
View
2  test/test_qadmin_configuration.rb
@@ -17,7 +17,7 @@ class TestQadminConfiguration < Test::Unit::TestCase
should "create special config objects for each action" do
@configuration.available_actions.each do |action|
- assert_equal "Qadmin::Configuration::Actions::#{action.to_s.classify}", @configuration["on_#{action}"].class.to_s
+ assert_equal "Qadmin::Configuration::Actions::#{action.to_s.classify}", @configuration.send("on_#{action}").class.to_s
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.