# Include hook code here # require 'randomizer.rb' # Must have a defined source of entropy for the GameDSL to work. This class # is responsible for determining the required source and getting it initialized # and ready to go. class EntropyInitializer DEFAULT_ENTROPY_CONFIGURATION_FILENAME = 'entropy.yml' # Instantiate and configure the selected entropy source. def self.initialize_entropy_source entropy_configuration = self.load_entropy_configuration require "entropy_sources/#{entropy_configuration[RAILS_ENV]['source']}_entropy_source" entropy_source_class_name = entropy_configuration[RAILS_ENV]['source'].camelize eval "GameDSL::EntropySources::#{entropy_source_class_name}EntropySource.configure_entropy_source(entropy_configuration[RAILS_ENV])" entropy_source = eval "GameDSL::EntropySources::#{entropy_source_class_name}EntropySource.get_entropy_source" GameDSL::EntropySources::EntropySource.set_entropy_source(entropy_source) end # Loads and returns the contents of the #entropy_configuration_file. The # contents of the file are processed via ERB before being sent through # YAML::load. def self.load_entropy_configuration if File.exists?(entropy_configuration_file) YAML::load(ERB.new(IO.read(entropy_configuration_file)).result) else # set up a safe default if there is no configuration file { RAILS_ENV => {'source' => 'kernel', 'seed' => 0 } } end end # Returns the name of the entropy configuration file. This is entropy.yml by # default. This will allow later configuration of the location and name of this # file. def self.entropy_configuration_file self.default_entropy_configuration_file end private # Full path and name for the default entropy configuration file. This is # currently RAILS_ROOT/config/entropy.yml def self.default_entropy_configuration_file File.join(RAILS_ROOT, 'config', DEFAULT_ENTROPY_CONFIGURATION_FILENAME) end end # Setup code goes here require 'entropy_source' EntropyInitializer.initialize_entropy_source require 'integer' require 'acts_as_deck'