module Cda::StrictAttributes

Public Class Methods

new(attributes = nil) click to toggle source

noinspection RubySuperCallWithoutSuperclassInspection

Calls superclass method
# File lib/cda/strict_attributes.rb, line 4
def initialize(attributes = nil)
  check_attributes_allowed(attributes) if !attributes.nil? && attributes.is_a?(Hash)
  super
end

Public Instance Methods

check_attributes_allowed(attributes) click to toggle source
# File lib/cda/strict_attributes.rb, line 9
def check_attributes_allowed(attributes)
  wrong_attributes = attributes.keys.reject { |attr| allowed_writer_methods.include?("#{attr}=") }
  unless wrong_attributes.empty?
    raise ArgumentError, "You have invalid attributes in initialization hash (for #{self.class.name}): #{wrong_attributes.join(', ')}"
  end
end