Module: GollumRails::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Page, Upload
Defined in:
lib/gollum_rails/attributes.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes) ⇒ Object

Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute name

new_attributes - Hash - Hash of arguments


9
10
11
12
13
14
15
16
17
18
# File 'lib/gollum_rails/attributes.rb', line 9

def assign_attributes(new_attributes)
  if !new_attributes.respond_to?(:stringify_keys)
    raise ArgumentError, "When assigning attributes, you must pass a hash as an argument."
  end
  return if new_attributes.blank?
  attributes = new_attributes.stringify_keys
  attributes.each do |k, v|
    _assign_attribute(k, v)
  end
end