Class: Chouette::TridentActiveRecord
Direct Known Subclasses
AccessLink, AccessPoint, Company, ConnectionLink, GroupOfLine, JourneyPattern, Line, Network, Route, StopArea, StopPoint, TimeTable, VehicleJourney
Class Method Summary
collapse
Instance Method Summary
collapse
#human_attribute_name, #nil_if_blank, nullable_attributes
Class Method Details
.model_name ⇒ Object
104
105
106
|
# File 'app/models/chouette/trident_active_record.rb', line 104
def self.model_name
ActiveModel::Name.new self, Chouette, self.name.demodulize
end
|
.object_id_key ⇒ Object
triggers to generate objectId and objectVersion TODO setting prefix in referential object
12
13
14
|
# File 'app/models/chouette/trident_active_record.rb', line 12
def self.object_id_key
model_name
end
|
Instance Method Details
#build_objectid ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'app/models/chouette/trident_active_record.rb', line 69
def build_objectid
if self.objectid.include? ':__pending_id__'
fix_uniq_objectid
self.update_attributes( :objectid => self.objectid, :object_version => (self.object_version - 1) )
end
end
|
#clean_object_id ⇒ Object
49
50
51
52
53
|
# File 'app/models/chouette/trident_active_record.rb', line 49
def clean_object_id
if self.objectid.include?("__pending_id__")
self.objectid=nil
end
end
|
#default_values ⇒ Object
121
122
123
|
# File 'app/models/chouette/trident_active_record.rb', line 121
def default_values
self.object_version ||= 1
end
|
#fix_uniq_objectid ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/models/chouette/trident_active_record.rb', line 55
def fix_uniq_objectid
base_objectid = self.objectid.rpartition(":").first
self.objectid = "#{base_objectid}:#{self.id}"
if !self.valid?
base_objectid="#{self.objectid}_"
cnt=1
while !self.valid?
self.objectid = "#{base_objectid}#{cnt}"
cnt += 1
end
end
end
|
#objectid ⇒ Object
108
109
110
|
# File 'app/models/chouette/trident_active_record.rb', line 108
def objectid
Chouette::ObjectId.new read_attribute(:objectid)
end
|
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/models/chouette/trident_active_record.rb', line 83
def objectid_format_compliance
if !self.objectid.valid?
errors.add(:objectid,I18n.t("activerecord.errors.models.trident.invalid_object_id",:type => self.class.object_id_key))
else
unless self.objectid.object_type==self.class.object_id_key
errors.add(:objectid,I18n.t("activerecord.errors.models.trident.invalid_object_id_type",:type => self.class.object_id_key))
end
end
end
|
#prefix ⇒ Object
16
17
18
|
# File 'app/models/chouette/trident_active_record.rb', line 16
def prefix
"NINOXE"
end
|
#prepare_auto_columns ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/chouette/trident_active_record.rb', line 19
def prepare_auto_columns
if self.objectid.nil? || self.objectid.blank?
if self.id.nil?
self.objectid = "#{prefix}:#{self.class.object_id_key}:__pending_id__#{rand(1000)}"
else
self.objectid = "#{prefix}:#{self.class.object_id_key}:#{self.id}"
fix_uniq_objectid
end
elsif not self.objectid.include? ':'
self.objectid = "#{prefix}:#{self.class.object_id_key}:#{self.objectid}"
end
if self.object_version.nil?
self.object_version = 1
else
self.object_version += 1
end
self.creation_time = Time.now
self.creator_id = 'chouette'
end
|
#reset_auto_columns ⇒ Object
45
46
47
|
# File 'app/models/chouette/trident_active_record.rb', line 45
def reset_auto_columns
clean_object_id unless self.errors.nil? || self.errors.empty?
end
|
#timestamp_attributes_for_create ⇒ Object
129
130
131
|
# File 'app/models/chouette/trident_active_record.rb', line 129
def timestamp_attributes_for_create [:creation_time]
end
|
#timestamp_attributes_for_update ⇒ Object
125
126
127
|
# File 'app/models/chouette/trident_active_record.rb', line 125
def timestamp_attributes_for_update [:creation_time]
end
|
#uniq_objectid ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'app/models/chouette/trident_active_record.rb', line 95
def uniq_objectid
i = 0
baseobjectid = self.objectid
while self.class.exists?(:objectid => self.objectid)
i += 1
self.objectid = baseobjectid+"_"+i.to_s
end
end
|