module Neo4j::Shared::MassAssignment

MassAssignment allows you to bulk set and update attributes

Including MassAssignment into your model gives it a set of mass assignment methods, similar to those found in ActiveRecord.

@example Usage

class Person
  include Neo4j::Shared::MassAssignment
end

Originally part of ActiveAttr, github.com/cgriego/active_attr

Public Class Methods

new(attributes = nil) click to toggle source

Initialize a model with a set of attributes

@example Initializing with a hash

person = Person.new(:first_name => "Chris", :last_name => "Griego")
person.first_name #=> "Chris"
person.last_name #=> "Griego"

@param (see assign_attributes)

Calls superclass method
   # File lib/neo4j/shared/mass_assignment.rb
53 def initialize(attributes = nil)
54   assign_attributes(attributes)
55   super()
56 end

Public Instance Methods

assign_attributes(new_attributes = nil) click to toggle source

Mass update a model’s attributes

@example Assigning a hash

person.assign_attributes(:first_name => "Chris", :last_name => "Griego")
person.first_name #=> "Chris"
person.last_name #=> "Griego"

@param [Hash{#to_s => Object}, each] attributes Attributes used to

populate the model

@param [Hash, []] options Options that affect mass assignment

   # File lib/neo4j/shared/mass_assignment.rb
25 def assign_attributes(new_attributes = nil)
26   return unless new_attributes.present?
27   new_attributes.each do |name, value|
28     writer = :"#{name}="
29     send(writer, value) if respond_to?(writer)
30   end
31 end
attributes=(new_attributes) click to toggle source

Mass update a model’s attributes

@example Assigning a hash

person.attributes = { :first_name => "Chris", :last_name => "Griego" }
person.first_name #=> "Chris"
person.last_name #=> "Griego"

@param (see assign_attributes)

   # File lib/neo4j/shared/mass_assignment.rb
41 def attributes=(new_attributes)
42   assign_attributes(new_attributes)
43 end