Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_extensions_plugins / plugins / scenarios / lib / scenarios / extensions / .svn / text-base / string.rb.svn-base
blob830aa791407b9b9928514ef894d3268b7ef93bb0
1 class String
2   
3   # Convert a string into the associated scenario class:
4   #
5   #   "basic".to_scenario #=> BasicScenario
6   #   "basic_scenario".to_scenario #=> BasicScenario
7   #
8   # Raises Scenario::NameError if the the scenario cannot be loacated in
9   # Scenario.load_paths.
10   def to_scenario
11     class_name = "#{self.strip.camelize.sub(/Scenario$/, '')}Scenario"
12     Scenario.load_paths.each do |path|
13       filename = "#{path}/#{class_name.underscore}.rb"
14       if File.file?(filename)
15         require filename
16         break
17       end
18     end
19     class_name.constantize rescue raise Scenario::NameError, "Expected to find #{class_name} in #{Scenario.load_paths.inspect}"
20   end
21   
22 end