Class: Taza::Settings
Constant Summary collapse
- @@root =
nil
Class Method Summary collapse
-
.config(site_name = nil) ⇒ Object
The config settings from the site.yml and config.yml files.
-
.config_file ⇒ Object
Returns a hash corresponding to the project config file.
-
.config_file_path ⇒ Object
:nodoc:.
- .convert_string_keys_to_symbols(hash) ⇒ Object
- .environment ⇒ Object
-
.environment_settings ⇒ Object
Returns a hash for the currently specified test environment.
-
.path ⇒ Object
:nodoc:.
- .path=(path) ⇒ Object
- .to_bool(value) ⇒ Object
Class Method Details
.config(site_name = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/taza/settings.rb', line 11 def config(site_name=nil) keys = %w(browser driver timeout server_ip server_port visible speed attach leave_open bring_to_front) default_settings = { :browser => 'firefox', :driver => 'watir', :visible => true, :speed => 'fast', :attach => false, :bring_to_front => false, :leave_open => false, } env_settings = {} keys.each do |key| env_settings[key.to_sym] = ENV[key.upcase] if ENV[key.upcase] end # Because of the way #merge works, the settings at the bottom of the list # trump those at the top. settings = default_settings.merge( environment_settings.merge( config_file.merge( env_settings))) settings[:browser] = settings[:browser].to_s settings[:driver] = settings[:driver].to_s settings[:speed] = settings[:speed].to_sym settings[:visible] = to_bool(settings[:visible]) settings[:leave_open] = to_bool(settings[:leave_open]) settings[:attach] = to_bool(settings[:attach]) settings[:bring_to_front] = to_bool(settings[:bring_to_front]) settings end |
.config_file ⇒ Object
Returns a hash corresponding to the project config file.
46 47 48 49 50 51 52 53 |
# File 'lib/taza/settings.rb', line 46 def config_file if File.exists?(config_file_path) hash = YAML.load_file(config_file_path) else hash = {} end convert_string_keys_to_symbols hash end |
.config_file_path ⇒ Object
:nodoc:
55 56 57 |
# File 'lib/taza/settings.rb', line 55 def config_file_path # :nodoc: File.join(path, 'config', 'config.yml') end |
.convert_string_keys_to_symbols(hash) ⇒ Object
83 84 85 86 87 |
# File 'lib/taza/settings.rb', line 83 def convert_string_keys_to_symbols hash returning Hash.new do |new_hash| hash.each_pair {|k, v| new_hash[k.to_sym] = v} end end |
.environment ⇒ Object
79 80 81 |
# File 'lib/taza/settings.rb', line 79 def environment ENV['ENVIRONMENT'] || 'test' end |
.environment_settings ⇒ Object
Returns a hash for the currently specified test environment
60 61 62 63 64 65 66 67 |
# File 'lib/taza/settings.rb', line 60 def environment_settings # :nodoc: file = File.join(path, environment_file) hash_of_hashes = YAML.load_file(file) unless hash_of_hashes.has_key? environment raise "Environment #{environment} not found in #{file}" end convert_string_keys_to_symbols hash_of_hashes[environment] end |
.path ⇒ Object
:nodoc:
71 72 73 |
# File 'lib/taza/settings.rb', line 71 def path # :nodoc: @@root || APP_ROOT end |
.path=(path) ⇒ Object
75 76 77 |
# File 'lib/taza/settings.rb', line 75 def path= path @@root = path end |
.to_bool(value) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/taza/settings.rb', line 89 def to_bool value case value when true, /true/i true else false end end |