Class: Neo4j::Model
- Inherits:
-
Object
show all
- Extended by:
- ActiveModel::Callbacks
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, DelayedSave, NodeMixin
- Defined in:
- lib/neo4j/model.rb
Defined Under Namespace
Classes: RecordInvalidError
Class Method Summary
collapse
Instance Method Summary
collapse
#[], #[]=, #id, #init_with_node, #init_without_node, #reload, #save
Class Method Details
.all ⇒ Object
71
72
73
|
# File 'lib/neo4j/model.rb', line 71
def self.all
super.nodes
end
|
.create(*args) ⇒ Object
84
85
86
|
# File 'lib/neo4j/model.rb', line 84
def self.create(*args)
new(*args).tap {|model| model.save }
end
|
.create!(*args) ⇒ Object
88
89
90
|
# File 'lib/neo4j/model.rb', line 88
def self.create!(*args)
new(*args).tap {|model| model.save! }
end
|
.find(*args) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/neo4j/model.rb', line 76
def self.find(*args)
if args.length == 1 && String === args[0] && args[0].to_i != 0
load(*args)
else
super
end
end
|
.inherited(subc) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/neo4j/model.rb', line 92
def self.inherited(subc) subc.instance_eval do
def root_class
self
end
end
end
|
.load(*ids) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/neo4j/model.rb', line 62
def self.load(*ids)
result = ids.map {|id| Neo4j.load_node(id) }
if ids.length == 1
result.first
else
result
end
end
|
Instance Method Details
#attributes=(attrs) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/neo4j/model.rb', line 30
def attributes=(attrs)
attrs.each do |k,v|
if respond_to?("#{k}=")
send("#{k}=", v)
else
self[k] = v
end
end
end
|
#destroy ⇒ Object
50
51
52
53
54
|
# File 'lib/neo4j/model.rb', line 50
def destroy
_run_destroy_callbacks do
del
end
end
|
#persisted? ⇒ Boolean
22
23
24
|
# File 'lib/neo4j/model.rb', line 22
def persisted?
@persisted
end
|
#read_attribute_for_validation(key) ⇒ Object
26
27
28
|
# File 'lib/neo4j/model.rb', line 26
def read_attribute_for_validation(key)
self[key]
end
|
#save! ⇒ Object
56
57
58
59
60
|
# File 'lib/neo4j/model.rb', line 56
def save!
unless save
raise RecordInvalidError.new(self)
end
end
|
#update_attributes(attributes) ⇒ Object
40
41
42
43
|
# File 'lib/neo4j/model.rb', line 40
def update_attributes(attributes)
self.attributes = attributes
save
end
|
#update_attributes!(attributes) ⇒ Object
45
46
47
48
|
# File 'lib/neo4j/model.rb', line 45
def update_attributes!(attributes)
self.attributes = attributes
save!
end
|