diff options
| author | cedricnjanga | 2017-11-16 16:10:48 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-17 10:49:01 +0100 |
| commit | 0f7da86d0a54d84f9f9f5683b2bb95a106158373 (patch) | |
| tree | e0e930a927a2367b5ef7fe2a1906da5dc2e96c16 /app/models/chouette | |
| parent | 8cbad698e0fe517602bca4b82ae60795eca12ab0 (diff) | |
| download | chouette-core-0f7da86d0a54d84f9f9f5683b2bb95a106158373.tar.bz2 | |
Create objectid format and integrate it in models. Work in progress. Refs #4941
Diffstat (limited to 'app/models/chouette')
| -rw-r--r-- | app/models/chouette/netex_object_id.rb | 40 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formater/netex.rb | 18 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formater/stif_codifligne.rb | 18 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formater/stif_netex.rb | 20 | ||||
| -rw-r--r-- | app/models/chouette/objectid_formater/stif_reflex.rb | 18 | ||||
| -rw-r--r-- | app/models/chouette/stif_codifligne_objectid.rb | 18 | ||||
| -rw-r--r-- | app/models/chouette/stif_netex_objectid.rb | 42 | ||||
| -rw-r--r-- | app/models/chouette/stif_reflex_objectid.rb | 18 |
8 files changed, 74 insertions, 118 deletions
diff --git a/app/models/chouette/netex_object_id.rb b/app/models/chouette/netex_object_id.rb deleted file mode 100644 index 441004c1e..000000000 --- a/app/models/chouette/netex_object_id.rb +++ /dev/null @@ -1,40 +0,0 @@ -class Chouette::NetexObjectId < String - - def valid? - parts.present? - end - alias_method :objectid?, :valid? - - @@format = /^([A-Za-z_]+):([0-9A-Za-z_]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def provider_id - parts.try(:first) - end - - def system_id - parts.try(:second) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - - def self.create(provider_id, system_id, object_type, local_id) - new [provider_id, system_id, object_type, local_id].join(":") - end - - def self.new(string) - string ||= "" - self === string ? string : super - end - -end diff --git a/app/models/chouette/objectid_formater/netex.rb b/app/models/chouette/objectid_formater/netex.rb new file mode 100644 index 000000000..0736b6ff9 --- /dev/null +++ b/app/models/chouette/objectid_formater/netex.rb @@ -0,0 +1,18 @@ +module Chouette + module ObjectidFormater + class Netex + def before_validation(model) + model.objectid ||= Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub(/Chouette::/,'')).to_s + end + + def after_commit(model) + # unused method in this context + end + + def parse_objectid(definition) + parts = definition.split(":") + Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]).to_s rescue nil + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formater/stif_codifligne.rb b/app/models/chouette/objectid_formater/stif_codifligne.rb new file mode 100644 index 000000000..53fd28c82 --- /dev/null +++ b/app/models/chouette/objectid_formater/stif_codifligne.rb @@ -0,0 +1,18 @@ +module Chouette + module ObjectidFormater + class StifCodifligne + def before_validation(model) + # unused method in this context + end + + def after_commit(model) + # unused method in this context + end + + def parse_objectid(definition) + parts = definition.split(":") + Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3]).to_s rescue nil + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formater/stif_netex.rb b/app/models/chouette/objectid_formater/stif_netex.rb new file mode 100644 index 000000000..88995dd05 --- /dev/null +++ b/app/models/chouette/objectid_formater/stif_netex.rb @@ -0,0 +1,20 @@ +module Chouette + module ObjectidFormater + class StifNetex + def before_validation(model) + model.objectid ||= "__pending_id__#{rand(50)+ rand(50)}" + end + + def after_commit(model) + if model.objectid.include? ':__pending_id__' + model.objectid = Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub(/Chouette::/,''), local_id: model.local_id).to_s + end + end + + def parse_objectid(definition) + parts = definition.split(":") + Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]).to_s rescue nil + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formater/stif_reflex.rb b/app/models/chouette/objectid_formater/stif_reflex.rb new file mode 100644 index 000000000..e6c6a6a70 --- /dev/null +++ b/app/models/chouette/objectid_formater/stif_reflex.rb @@ -0,0 +1,18 @@ +module Chouette + module ObjectidFormater + class StifReflex + def before_validation(model) + # unused method in this context + end + + def after_commit(model) + # unused method in this context + end + + def parse_objectid(definition) + parts = definition.split(":") + Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4]).to_s rescue nil + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/stif_codifligne_objectid.rb b/app/models/chouette/stif_codifligne_objectid.rb deleted file mode 100644 index 46109e24f..000000000 --- a/app/models/chouette/stif_codifligne_objectid.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Chouette::StifCodifligneObjectid < String - - @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - -end diff --git a/app/models/chouette/stif_netex_objectid.rb b/app/models/chouette/stif_netex_objectid.rb deleted file mode 100644 index 93e7a1e85..000000000 --- a/app/models/chouette/stif_netex_objectid.rb +++ /dev/null @@ -1,42 +0,0 @@ -class Chouette::StifNetexObjectid < String - def valid? - parts.present? - end - - @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def provider_id - parts.try(:first) - end - - def object_type - parts.try(:second) - end - - def local_id - parts.try(:third) - end - - def boiv_id - parts.try(:fourth) - end - - def short_id - local_id.try(:split, "-").try(:[], -1) - end - - def self.create(provider_id, object_type, local_id, boiv_id) - new [provider_id, object_type, local_id, boiv_id].join(":") - end - - def self.new(string) - string ||= "" - self === string ? string : super - end - -end diff --git a/app/models/chouette/stif_reflex_objectid.rb b/app/models/chouette/stif_reflex_objectid.rb deleted file mode 100644 index c41a9325a..000000000 --- a/app/models/chouette/stif_reflex_objectid.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Chouette::StifReflexObjectid < String - - @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - -end |
