Sha256: f1d2cbe826029a1e37e90ac32d2fb37639d4da212c6c60c716151d4265d35a3b
Contents?: true
Size: 950 Bytes
Versions: 1
Compression:
Stored size: 950 Bytes
Contents
# frozen_string_literal: true module TableSync::Utils::RequiredValidator module PrependedInitialization def initialize(*) super not_filled_attrs = calculate_not_filled_attributes if not_filled_attrs.present? raise( ArgumentError, "Some of required attributes is not provided: #{not_filled_attrs.inspect}", ) end end end module ClassMethods def require_attributes(*attributes) _required_attributes.push(*attributes) end def _required_attributes @_required_attributes ||= [] end end module InstanceMethods private def calculate_not_filled_attributes attributes .select { |key, value| key.in?(self.class._required_attributes) && value.blank? } .keys end end def self.included(klass) klass.prepend(PrependedInitialization) klass.extend(ClassMethods) klass.include(InstanceMethods) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
table_sync-6.4.1 | lib/table_sync/utils/required_validator.rb |