Sha256: 2c636385303c29cf86da1ca2e3e4b04984bddb328953ae8de99149153aae26fb

Contents?: true

Size: 715 Bytes

Versions: 2

Compression:

Stored size: 715 Bytes

Contents

# frozen_string_literal: true

require 'delegate'

module Masking
  class InsertStatement
    class Value < ::SimpleDelegator
      def initialize(columns:, data:)
        @columns = columns
        @data    = Struct.new(*columns).new(*data)
        # NOTE: is it better to get rid of SimpleDelegator, store data in instance variable and define accesor for it?
        super(@data)
      end

      def phrase
        '(' + to_a.join(?,) + ')'
      end

      # override for make comparable
      # NOTE: original #== method comapares struct subclass
      def ==(other)
        to_h == other.to_h
      end

      def column?(column_name)
        @columns.include?(column_name.to_sym)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masking-0.0.2 lib/masking/insert_statement/value.rb
masking-0.0.1 lib/masking/insert_statement/value.rb