Module: Neo4j::Shared::MassAssignment
- Extended by:
- ActiveSupport::Concern
- Included in:
- Property
- Defined in:
- lib/neo4j/shared/mass_assignment.rb
Overview
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.
Originally part of ActiveAttr, github.com/cgriego/active_attr
Instance Method Summary collapse
- #add_undeclared_property(_, _) ⇒ Object
-
#assign_attributes(new_attributes = nil) ⇒ Object
Mass update a model’s attributes.
-
#attributes=(new_attributes) ⇒ Object
Mass update a model’s attributes.
-
#initialize(attributes = nil) ⇒ Object
Initialize a model with a set of attributes.
Instance Method Details
#add_undeclared_property(_, _) ⇒ Object
37 |
# File 'lib/neo4j/shared/mass_assignment.rb', line 37 def add_undeclared_property(_, _); end |
#assign_attributes(new_attributes = nil) ⇒ Object
Mass update a model’s attributes
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/neo4j/shared/mass_assignment.rb', line 25 def assign_attributes(new_attributes = nil) return unless new_attributes.present? new_attributes.each do |name, value| writer = :"#{name}=" if respond_to?(writer) send(writer, value) else add_undeclared_property(name, value) end end end |
#attributes=(new_attributes) ⇒ Object
Mass update a model’s attributes
47 48 49 |
# File 'lib/neo4j/shared/mass_assignment.rb', line 47 def attributes=(new_attributes) assign_attributes(new_attributes) end |
#initialize(attributes = nil) ⇒ Object
Initialize a model with a set of attributes
59 60 61 62 |
# File 'lib/neo4j/shared/mass_assignment.rb', line 59 def initialize(attributes = nil) assign_attributes(attributes) super() end |