module Executrix::Helper

Constants

CSV_OPTIONS

Public Instance Methods

absolute_to_relative_path(input, replacement) click to toggle source
# File lib/executrix/helper.rb, line 69
def absolute_to_relative_path input, replacement
  input.gsub(/(^C:[\/\\])|(^\/)/,replacement)
end
attachment_keys(records) click to toggle source
# File lib/executrix/helper.rb, line 45
def attachment_keys records
  records.map do |record|
    record.select do |key, value|
      value.class == File
    end.keys
  end.flatten.uniq
end
fetch_instance_from_server_url(server_url) click to toggle source
# File lib/executrix/helper.rb, line 40
def fetch_instance_from_server_url server_url
  before_sf = server_url[/^https?:\/\/(.+)\.salesforce\.com/, 1]
  before_sf.gsub(/-api$/,'')
end
parse_csv(csv_string) click to toggle source
# File lib/executrix/helper.rb, line 73
def parse_csv csv_string
  CSV.parse(csv_string, headers: true).map{|r| r.to_hash}
end
records_to_csv(records) click to toggle source
# File lib/executrix/helper.rb, line 13
def records_to_csv records
  file_mock = StringIO.new
  csv_client = CSV.new(file_mock, CSV_OPTIONS)
  all_headers = []
  all_rows = []
  records.each do |hash|
    row = CSV::Row.new([],[],false)
    to_store = hash.inject({}) do |h, (k, v)|
      if v == nil || v == '' || v == []
        h[k] = '#N/A'
      else
        h[k] = v.class == Array ? v.join(';') : v
      end
      h
    end
    row << to_store
    all_headers << row.headers
    all_rows << row
  end
  all_headers.flatten!.uniq!
  csv_client << all_headers
  all_rows.each do |row|
    csv_client << row.fields(*all_headers)
  end
  file_mock.string
end
transform_values!(records, keys) { |file_path| ... } click to toggle source
# File lib/executrix/helper.rb, line 53
def transform_values! records, keys
  keys.each do |key|
    records.each do |record|
      file_handle = record[key]
      if file_handle
        file_path = File.absolute_path(file_handle)
        record
          .merge!({
            key => Executrix::Helper.absolute_to_relative_path(file_path,'#')
          })
        yield file_path if block_given?
      end
    end
  end
end