Class: OrientDB::AR::Base
- Inherits:
-
Object
- Object
- OrientDB::AR::Base
show all
- Extended by:
- Relations
- Includes:
- ActiveModel::AttributeMethods, DocumentMixin
- Defined in:
- lib/orientdb-ar/base.rb
Class Attribute Summary collapse
#odocument
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Relations
embedds_many, embedds_one, links_many, links_one
#<=>, #connection, #embedded?, #field?, #human_id, included, #initialize, #inspect, #method_missing, #oclass, #oclass_name, #related, #related_valid?, #respond_to?, #rid, #valid_with_default_group?, #validate, #validate_to_parent
Class Attribute Details
.oclass_name=(value) ⇒ Object
Sets the attribute oclass_name
67
68
69
|
# File 'lib/orientdb-ar/base.rb', line 67
def oclass_name=(value)
@oclass_name = value
end
|
Class Method Details
.all(conditions = { }) ⇒ Object
127
128
129
|
# File 'lib/orientdb-ar/base.rb', line 127
def all(conditions = { })
OrientDB::AR::Query.new(self).where(conditions).all
end
|
.clear ⇒ Object
151
152
153
|
# File 'lib/orientdb-ar/base.rb', line 151
def clear
oclass.truncate
end
|
.count ⇒ Object
147
148
149
|
# File 'lib/orientdb-ar/base.rb', line 147
def count
oclass.count
end
|
.create(fields = { }) ⇒ Object
99
100
101
102
103
|
# File 'lib/orientdb-ar/base.rb', line 99
def create(fields = { })
obj = new fields
obj.save
obj
end
|
.delete(*args) ⇒ Object
139
140
141
|
# File 'lib/orientdb-ar/base.rb', line 139
def delete(*args)
OrientDB::AR::Delete.new(self).where(*args).run
end
|
.descends_from_base? ⇒ Boolean
95
96
97
|
# File 'lib/orientdb-ar/base.rb', line 95
def descends_from_base?
superclass && superclass == OrientDB::AR::Base
end
|
.embeddable? ⇒ Boolean
69
70
71
|
# File 'lib/orientdb-ar/base.rb', line 69
def embeddable?
false
end
|
.field(name, type, options = { }) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/orientdb-ar/base.rb', line 86
def field(name, type, options = { })
name = name.to_sym
if fields.key? name
puts "Already defined field [#{name}]"
else
fields[name] = { :type => type }.update options
end
end
|
.first(conditions = { }) ⇒ Object
131
132
133
|
# File 'lib/orientdb-ar/base.rb', line 131
def first(conditions = { })
OrientDB::AR::Query.new(self).where(conditions).first
end
|
.insert(*args) ⇒ Object
143
144
145
|
# File 'lib/orientdb-ar/base.rb', line 143
def insert(*args)
from_orientdb OrientDB::AR::Insert.new(self).fields(*args).run
end
|
.limit(max_records) ⇒ Object
119
120
121
|
# File 'lib/orientdb-ar/base.rb', line 119
def limit(max_records)
OrientDB::AR::Query.new(self).limit(max_records)
end
|
.oclass ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/orientdb-ar/base.rb', line 73
def oclass
unless defined?(@oclass)
options = { }
unless descends_from_base?
super_oclass = superclass.oclass
options[:super] = super_oclass
options[:use_cluster] = super_oclass.cluster_ids.first
end
@oclass = connection.get_or_create_class oclass_name, options
end
@oclass
end
|
.order(*args) ⇒ Object
115
116
117
|
# File 'lib/orientdb-ar/base.rb', line 115
def order(*args)
OrientDB::AR::Query.new(self).order(*args)
end
|
.range(lower_rid, upper_rid = nil) ⇒ Object
123
124
125
|
# File 'lib/orientdb-ar/base.rb', line 123
def range(lower_rid, upper_rid = nil)
OrientDB::AR::Query.new(self).range(lower_rid, upper_rid)
end
|
.select(*args) ⇒ Object
Also known as:
columns
105
106
107
|
# File 'lib/orientdb-ar/base.rb', line 105
def select(*args)
OrientDB::AR::Query.new(self).select(*args)
end
|
.update(*args) ⇒ Object
135
136
137
|
# File 'lib/orientdb-ar/base.rb', line 135
def update(*args)
OrientDB::AR::Update.new(self).values(*args).run
end
|
.where(*args) ⇒ Object
111
112
113
|
# File 'lib/orientdb-ar/base.rb', line 111
def where(*args)
OrientDB::AR::Query.new(self).where(*args)
end
|
Instance Method Details
#delete ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/orientdb-ar/base.rb', line 35
def delete
_run_delete_callbacks do
@odocument.delete
@deleted = true
end
true
end
|
#deleted? ⇒ Boolean
55
56
57
|
# File 'lib/orientdb-ar/base.rb', line 55
def deleted?
@deleted ||= false
end
|
#persisted? ⇒ Boolean
59
60
61
|
# File 'lib/orientdb-ar/base.rb', line 59
def persisted?
saved? && !deleted?
end
|
#reload ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/orientdb-ar/base.rb', line 43
def reload
raise "Not persisted, cannot reload" unless persisted?
@odocument = OrientDB::AR::Query.new(self.class).where('@rid' => rid.lit).first_result
@changed_attributes = { }
@errors = ActiveModel::Errors.new(self)
self
end
|
#save(perform_validations = true) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/orientdb-ar/base.rb', line 10
def save(perform_validations = true)
_run_save_callbacks do
if perform_validations
validate
if @last_validation_result
save_without_validations
else
false
end
else
save_without_validations
end
end
end
|
#saved? ⇒ Boolean
51
52
53
|
# File 'lib/orientdb-ar/base.rb', line 51
def saved?
@saved || @odocument.rid != '-1:-1'
end
|