Changeset 176

Show
Ignore:
Timestamp:
04/19/08 12:23:10 (7 months ago)
Author:
eric.dumin..@gmail.com
Message:

Some doc & refactoring for models/document.rb

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/oo_indexer/lib/picolena/templates/app/models/document.rb

    r170 r176  
    22class Document 
    33  attr_reader :complete_path 
    4   attr_accessor :user, :score, :matching_content, :index_id 
     4  attr_writer :index_id 
     5  attr_accessor :user, :score, :matching_content 
    56   
    67  def initialize(path) 
     
    1011    validate_in_indexed_directory 
    1112  end 
    12    
    13   alias_method :to_param, :id 
    1413   
    1514  #Delegating properties to File::method_name(complete_path) 
     
    6665  # Returns content as it was at the time it was indexed. 
    6766  def cached 
    68     get_index_id! unless index_id 
    6967    IndexReader.new[index_id][:content] 
    7068  end 
    71    
     69  
     70  # FIXME: Not just date anymore. 
    7271  # Returns the last modification date before the document got indexed. 
    7372  # Useful to know how old a document is, and to which version the cache corresponds. 
    7473  def date 
    75     get_index_id! unless index_id 
    76     IndexReader.new[index_id][:date].sub(/(\d{4})(\d{2})(\d{2})/,'\1-\2-\3') 
     74    from_index[:date].sub(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,'\1-\2-\3 \4:\5:\6') 
    7775  end 
    7876   
    7977  def mtime 
    80     get_index_id! unless index_id 
    81     IndexReader.new[index_id][:date].to_i 
     78    from_index[:date].to_i 
     79  end 
     80 
     81  # Returns the id with which the document is indexed. 
     82  def index_id 
     83    @index_id ||= Document.find_by_complete_path(complete_path).index_id 
    8284  end 
    8385   
    8486  private 
    85    
    86   def get_index_id! 
    87     @index_id = Document.find_by_unique_id(probably_unique_id).index_id 
     87 
     88  # Retrieves the document from the index. 
     89  # Useful to get meta-info about it. 
     90  def from_index 
     91    IndexReader.new[index_id] 
    8892  end 
    8993   
  • branches/oo_indexer/lib/picolena/templates/app/views/documents/_document.html.haml

    r117 r176  
    44=highlight_matching_content(document) 
    55%p=link_to_containing_directory(document) 
    6 - if document.supported? 
     6-if document.supported? 
    77  %p 
    88    =link_to_plain_text_content(document)