Module: Zena::Use::VersionHash
- Defined in:
- lib/zena/use/version_hash.rb
Overview
This module takes care of deciding which version should be seen by whom (depending on access rights and language) by maintaining a ‘vhash’ entry. This module is also responsible for preloading versions during ‘many’ finds.
Technically, the vhash field contains two dictionaries “readonly” and “write”. Each of these dictionaries provide mapping from languages to version id.
{'r' => {'en' => 1234, 'fr' => 3456}, 'w' => {'en' => 5436, 'fr' => 4526}}
Defined Under Namespace
Modules: ModelMethods
Class Method Summary collapse
Class Method Details
.cached_values_from_records(records) ⇒ Object
12 13 14 15 16 17 18 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 44 45 46 47 48 49 50 |
# File 'lib/zena/use/version_hash.rb', line 12 def self.cached_values_from_records(records) r_hash, w_hash = {}, {} vhash = {'r' => r_hash, 'w' => w_hash} lang = nil n_pub = nil records.each do |record| if record['lang'] != lang lang = record['lang'] # highest status for this lang if record['status'].to_i == Zena::Status::Pub # ok for readers & writers w_hash[lang] = r_hash[lang] = record['id'].to_i v_pub = record['publish_from'] if v_pub.kind_of?(String) v_pub = DateTime.parse(record['publish_from']) rescue Time.now.utc end if n_pub.nil? || v_pub < n_pub n_pub = v_pub end else # too high, only ok for writers w_hash[lang] = record['id'].to_i end elsif record['status'].to_i == Zena::Status::Pub # ok for readers r_hash[lang] = record['id'].to_i v_pub = record['publish_from'] if v_pub.kind_of?(String) v_pub = DateTime.parse(record['publish_from']) rescue Time.now.utc end if n_pub.nil? || v_pub < n_pub n_pub = v_pub end end end {:publish_from => n_pub, :vhash => vhash} end |