Class: TestCentricity::EnvironData
- Inherits:
-
DataSource
- Object
- DataSource
- TestCentricity::EnvironData
- Defined in:
- lib/testcentricity_web/data_objects/environment.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#environ_specific_data ⇒ Object
Returns the value of attribute environ_specific_data.
-
#generic_data ⇒ Object
Returns the value of attribute generic_data.
Attributes inherited from DataSource
Class Method Summary collapse
Methods inherited from DataSource
#read_json_node_data, #read_yaml_node_data
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
3 4 5 |
# File 'lib/testcentricity_web/data_objects/environment.rb', line 3 def current @current end |
#environ_specific_data ⇒ Object
Returns the value of attribute environ_specific_data.
5 6 7 |
# File 'lib/testcentricity_web/data_objects/environment.rb', line 5 def environ_specific_data @environ_specific_data end |
#generic_data ⇒ Object
Returns the value of attribute generic_data.
4 5 6 |
# File 'lib/testcentricity_web/data_objects/environment.rb', line 4 def generic_data @generic_data end |
Class Method Details
.find_environ(environ_name, source_type = :yaml) ⇒ Object
7 8 9 10 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 |
# File 'lib/testcentricity_web/data_objects/environment.rb', line 7 def self.find_environ(environ_name, source_type = :yaml) raise 'No environment specified' if environ_name.nil? data = case source_type when :yaml # read generic test data from data.yml file @generic_data ||= YAML.load_file(YML_PRIMARY_DATA_FILE) # read environment specific test data data_file = "#{PRIMARY_DATA_PATH}#{environ_name}_data.yml" @environ_specific_data = if File.exist?(data_file) YAML.load_file(data_file) else {} end read('Environments', environ_name) when :json # read generic test data from data.json file raw_data = File.read(JSON_PRIMARY_DATA_FILE) @generic_data = JSON.parse(raw_data) # read environment specific test data data_file = "#{PRIMARY_DATA_PATH}#{environ_name}_data.json" @environ_specific_data = if File.exist?(data_file) raw_data = File.read(data_file) JSON.parse(raw_data) else {} end read('Environments', environ_name) else raise "#{source_type} is not a supported data source type" end @current = Environ.new(data) Environ.current = @current end |
.read(key_name, node_name) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/testcentricity_web/data_objects/environment.rb', line 44 def self.read(key_name, node_name) if @environ_specific_data.key?(key_name) && @environ_specific_data[key_name].key?(node_name) node_data = @environ_specific_data[key_name][node_name] else raise "No key named #{key_name} in generic and environment-specific data" unless @generic_data.key?(key_name) raise "No node named #{node_name} in #{key_name} section of generic and environment-specific data" unless @generic_data[key_name].key?(node_name) node_data = @generic_data[key_name][node_name] end if node_data.is_a?(Hash) node_data.each do |key, value| node_data[key] = calculate_dynamic_value(value) if value.to_s.start_with?('eval!') end end node_data end |