Frederick Cheung wrote:
> On Jun 14, 9:53�pm, nico Itkin <[email protected]>
> wrote:
>> But run whith rake everything fails :
>>
>> rake test:units
>>
>> => BOUM
>>
> How does it fail ? What is in constant_cache.rb ?
>
> Fred
The constant settings :
module ConstantCache
module ClassMethods
def cache_constants(field=nil)
find(:all).each do |instance|
if field and !instance.send(field).blank?
const = instance.send(field).gsub(/\s+/, '_').upcase
const_set(const, instance) unless const_defined?(const)
elsif field.nil?
const = instance.name.gsub(/\s+/, '_').upcase
const_set(const, instance) unless const_defined?(const)
end
end
end
def const_get(arg)
arg.is_a?(Symbol) ? super(arg.to_s.upcase) : super(arg)
end
end
end
ActiveRecord::Base.send(:extend, ConstantCache::ClassMethods)
For exemple in status_action.rb
class StatusAction < Action
cache_constants :name
has_many :statuses, :foreign_key=>'action_id'
end
... all the instance of type StatusAction become constants called
StatusAction::THE_RECORD_NAME_FIELD
well the strangest is that is contant_cache seems not to be correctly
run from rake...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---