module Hibp::Helpers::AttributeAssignment
Hibp::Helpers::AttributeAssignment
Used to assign attributes in models
Private Instance Methods
_assign_attribute(attr_name, attr_value)
click to toggle source
# File lib/hibp/helpers/attribute_assignment.rb, line 33 def _assign_attribute(attr_name, attr_value) return unless respond_to?("#{attr_name}=") public_send("#{attr_name}=", attr_value) end
assign_attributes(new_attributes)
click to toggle source
# File lib/hibp/helpers/attribute_assignment.rb, line 12 def assign_attributes(new_attributes) unless new_attributes.is_a?(Hash) raise ArgumentError, 'Attributes must be a Hash' end return if new_attributes.nil? || new_attributes.empty? attributes = stringify_keys(new_attributes) attributes.each { |k, v| _assign_attribute(k, v) } end
stringify_keys(hash)
click to toggle source
# File lib/hibp/helpers/attribute_assignment.rb, line 23 def stringify_keys(hash) transform_keys(hash, &:to_s) end
transform_keys(hash) { |key| ... }
click to toggle source
# File lib/hibp/helpers/attribute_assignment.rb, line 27 def transform_keys(hash) hash.each_with_object({}) do |(key, value), result| result[yield(key)] = value end end