class Masking::Config::TargetColumns

TODO: find better naming of TargetColumns

Attributes

file_path[R]

Public Class Methods

new(file_path) click to toggle source
# File lib/masking/config/target_columns.rb, line 14
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

Public Instance Methods

==(other) click to toggle source
# File lib/masking/config/target_columns.rb, line 30
def ==(other)
  file_path == other.file_path
end
columns(table_name:) click to toggle source

TODO: refactoring

# File lib/masking/config/target_columns.rb, line 26
def columns(table_name:)
  tables[table_name.to_sym]&.columns
end
contains?(table_name:) click to toggle source
# File lib/masking/config/target_columns.rb, line 21
def contains?(table_name:)
  data.key?(table_name)
end

Private Instance Methods

data() click to toggle source
# File lib/masking/config/target_columns.rb, line 36
def data
  @data ||= YAML.safe_load(file_path.read, [Date, Time])
rescue Psych::SyntaxError
  raise Masking::Error::ConfigFileIsNotValidYaml
end
tables() click to toggle source

TODO: extract to other class

# File lib/masking/config/target_columns.rb, line 43
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