Sha256: 774c20c7f19c2c4715c6d1945de64b92b76e969da5e6c68236916137c90d4b3a
Contents?: true
Size: 1.47 KB
Versions: 10
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true require 'csv' require 'erb' require 'singleton' module Workato module Connector module Sdk class AccountProperties include Singleton def self.from_yaml(path = DEFAULT_ACCOUNT_PROPERTIES_PATH) File.open(path) do |f| instance.load_data(YAML.safe_load(ERB.new(f.read).result, [::Symbol]).to_hash) end end def self.from_encrypted_yaml(path = DEFAULT_ENCRYPTED_ACCOUNT_PROPERTIES_PATH, key_path = nil) load_data( ActiveSupport::EncryptedConfiguration.new( config_path: path, key_path: key_path || DEFAULT_MASTER_KEY_PATH, env_key: DEFAULT_MASTER_KEY_ENV, raise_if_missing_key: true ).config ) end def self.from_csv(path = './account_properties.csv') props = CSV.foreach(path, headers: true, return_headers: false).map do |row| [row[0], row[1]] end.to_h instance.load_data(props) end class << self delegate :load_data, :get, :put, to: :instance end def get(key) @data ||= {} @data[key.to_s] end def put(key, value) @data ||= {} @data[key.to_s] = value.to_s end def load_data(props = {}) props.each { |k, v| put(k, v) } end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems