Sha256: 987e093d13497e0e04641380732fb2b5b5b46288162c2c483f07197fbfbd2131
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true require 'yaml' require 'masking/config/target_columns/table' require 'masking/config/target_columns/column' require 'masking/errors' module Masking class Config # TODO: find better naming of TargetColumns class TargetColumns attr_reader :file_path def initialize(file_path) @file_path = file_path raise Masking::Error::ConfigFileDoesNotExist unless file_path.exist? raise Masking::Error::ConfigFileIsNotFile unless file_path.file? end def contains?(table_name:) data.key?(table_name) end # TODO: refactoring def columns(table_name:) tables[table_name.to_sym]&.columns end def ==(other) file_path == other.file_path end private def data @data ||= YAML.safe_load(file_path.read, [Date, Time]) rescue Psych::SyntaxError raise Masking::Error::ConfigFileIsNotValidYaml end # TODO: extract to other class def tables @tables ||= data.each_with_object({}) do |kv, r| r[kv[0].to_sym] = Table.new(kv[0], columns: kv[1]) end rescue Masking::Config::TargetColumns::Column::ColumnNameIsNil raise Masking::Error::ConfigFileContainsNullAsColumnName end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
masking-1.0.1 | lib/masking/config/target_columns.rb |
masking-1.0.0 | lib/masking/config/target_columns.rb |