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 59 def initialize(attributes = nil) 60 assign_attributes(attributes) 61 super() 62 end
Public Instance Methods
add_undeclared_property(_, _)
click to toggle source
# File lib/neo4j/shared/mass_assignment.rb 37 def add_undeclared_property(_, _); end
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 if respond_to?(writer) 30 send(writer, value) 31 else 32 add_undeclared_property(name, value) 33 end 34 end 35 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 47 def attributes=(new_attributes) 48 assign_attributes(new_attributes) 49 end