Module: PopulateMe::DocumentMixins::Persistence::ClassMethods
- Defined in:
- lib/populate_me/document_mixins/persistence.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #id_string_key ⇒ Object
- #is_unique(unique_id = 'unique') ⇒ Object
- #set_indexes(f, ids = []) ⇒ Object
Instance Attribute Details
#documents ⇒ Object
66 |
# File 'lib/populate_me/document_mixins/persistence.rb', line 66 def documents; @documents ||= []; end |
Instance Method Details
#id_string_key ⇒ Object
68 69 70 |
# File 'lib/populate_me/document_mixins/persistence.rb', line 68 def id_string_key (self.fields.keys[0]||'id').to_s end |
#is_unique(unique_id = 'unique') ⇒ Object
84 85 86 87 88 |
# File 'lib/populate_me/document_mixins/persistence.rb', line 84 def is_unique unique_id='unique' if self.admin_get(unique_id).nil? self.new.set_from_hash({id:unique_id}).save end end |
#set_indexes(f, ids = []) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/populate_me/document_mixins/persistence.rb', line 72 def set_indexes f, ids=[] if self.fields and self.fields[f.to_sym] and self.fields[f.to_sym][:direction]==:desc ids = ids.dup.reverse end ids.each_with_index do |id,i| self.documents.each do |d| d[f.to_s] = i if d[self.id_string_key]==id end end self end |