class TestCentricity::DataSource

Attributes

file_path[RW]
node[RW]

Private Class Methods

calculate_dynamic_value(value) click to toggle source
# File lib/testcentricity_web/data_objects/data_objects_helper.rb, line 118
def self.calculate_dynamic_value(value)
  test_value = value.split('!', 2)
  parameter = test_value[1].split('.', 2)
  case parameter[0]
  when 'Date'
    result = eval("Chronic.parse('#{parameter[1]}')")
  when 'FormattedDate', 'FormatDate'
    date_time_params = parameter[1].split(' format! ', 2)
    date_time = eval("Chronic.parse('#{date_time_params[0].strip}')")
    result = date_time.to_s.format_date_time("#{date_time_params[1].strip}")
  else
    result = if Faker.constants.include?(parameter[0].to_sym)
               eval("Faker::#{parameter[0]}.#{parameter[1]}")
             else
               eval(test_value[1])
             end
  end
  result.to_s
end

Public Instance Methods

read_json_node_data(file_name, node_name) click to toggle source
# File lib/testcentricity_web/data_objects/data_objects_helper.rb, line 102
def read_json_node_data(file_name, node_name)
  @file_path = "#{PRIMARY_DATA_PATH}#{file_name}"
  @node = node_name
  raw_data = File.read(@file_path)
  data = JSON.parse(raw_data)
  data[node_name]
end
read_yaml_node_data(file_name, node_name) click to toggle source
# File lib/testcentricity_web/data_objects/data_objects_helper.rb, line 89
def read_yaml_node_data(file_name, node_name)
  @file_path = "#{PRIMARY_DATA_PATH}#{file_name}"
  @node = node_name
  data = YAML.load_file(@file_path)
  data[node_name]
end
write_json_node_data(file_name, node_name, node_data) click to toggle source
# File lib/testcentricity_web/data_objects/data_objects_helper.rb, line 110
def write_json_node_data(file_name, node_name, node_data)
  data = read_json_node_data(file_name, node_name)
  data[node_name] = node_data
  File.write(@file_path, data.to_json)
end
write_yaml_node_data(file_name, node_name, node_data) click to toggle source
# File lib/testcentricity_web/data_objects/data_objects_helper.rb, line 96
def write_yaml_node_data(file_name, node_name, node_data)
  data = read_yaml_node_data(file_name, node_name)
  data[node_name] = node_data
  File.write(@file_path, data.to_yaml)
end