Browse files

fix for bootstrapping

  • Loading branch information...
1 parent b83e67d commit fd78cabd9b1719d325c12a0521d49ad3dad08d08 @pschrammel committed May 16, 2009
Showing with 18 additions and 10 deletions.
  1. +18 −10 lib/active_acl/privilege_const_set.rb
View
28 lib/active_acl/privilege_const_set.rb
@@ -6,17 +6,25 @@ class ::Module
# If force_reload is set to true, the constant will be recreated from the DB.
# Returns an array of changed privileges.
def privilege_const_set(constant, force_reload = false)
- result = []
- constant.is_a?(Hash) ? constant_hash = constant : constant_hash = {constant.to_s => nil}
- constant_hash.each_pair do |constant_name, description|
- if !const_defined?(constant_name.to_s) || force_reload
- remove_const(constant_name.to_s) if const_defined?(constant_name.to_s)
- privilege = ActiveAcl::Privilege.find_by_section_and_value(self.name, constant_name.to_s)
- privilege = ActiveAcl::Privilege.create!(:section => self.name, :value => constant_name.to_s, :description => description) unless privilege
- const_set(constant_name.to_s, privilege)
- result << privilege
+ begin
+ result = []
+ constant.is_a?(Hash) ? constant_hash = constant : constant_hash = {constant.to_s => nil}
+ constant_hash.each_pair do |constant_name, description|
+ if !const_defined?(constant_name.to_s) || force_reload
+ remove_const(constant_name.to_s) if const_defined?(constant_name.to_s)
+ privilege = ActiveAcl::Privilege.find_by_section_and_value(self.name, constant_name.to_s)
+ privilege = ActiveAcl::Privilege.create!(:section => self.name, :value => constant_name.to_s, :description => description) unless privilege
+ const_set(constant_name.to_s, privilege)
+ result << privilege
+ end
end
+ result
+
+ #this is for bootstrapping
+ rescue NameError => e
+ puts "[ERROR] #{__FILE__},#{__LINE__}: Probably missing migration!\n#{e.inspect}"
+ rescue ActiveRecord::StatementInvalid => e
+ puts "[ERROR] #{__FILE__},#{__LINE__}: Probably missing migration!\n#{e.inspect}"
end
- result
end
end

0 comments on commit fd78cab

Please sign in to comment.