Module: MassAssignable::ClassMethods

Defined in:
lib/mass_assignable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#mass_assignable_attributesObject



16
17
18
# File 'lib/mass_assignable.rb', line 16

def mass_assignable_attributes
  @mass_assignable_attributes ||= []
end

#raise_on_invalid_mass_assignmentObject

Internal: Flag determining whether to raise an exception when you attempt to mass-assign attributes that are not allowed.



9
10
11
# File 'lib/mass_assignable.rb', line 9

def raise_on_invalid_mass_assignment
  @raise_on_invalid_mass_assignment
end

Instance Method Details

#attr_mass_assignable(*attributes) ⇒ Object

Public: Accepts a list of symbols representing instance methods that allow mass-assignment.

*attributes - An Array of symbols or strings.

Returns nothing.



26
27
28
29
30
# File 'lib/mass_assignable.rb', line 26

def attr_mass_assignable(*attributes)
  self.raise_on_invalid_mass_assignment = false
  self.mass_assignable_attributes ||= []
  self.mass_assignable_attributes.push(*attributes)
end

#attr_mass_assignable!(*attributes) ⇒ Object

Public: Accepts a list of symbols representing instance methods that allow mass-assignment and will raise an exception if mass assignment is attempted for attributes not specified here.

*attributes - An Array of symbols or strings.

Returns nothing.



39
40
41
42
# File 'lib/mass_assignable.rb', line 39

def attr_mass_assignable!(*attributes)
  attr_mass_assignable(*attributes)
  self.raise_on_invalid_mass_assignment = true
end