Skip to content

Commit

Permalink
Cleanup logic in Post.find_one() and allow loading draft articles in …
Browse files Browse the repository at this point in the history
…:development environment
  • Loading branch information
karmi committed Apr 13, 2009
1 parent dcbf44c commit da2a2e7
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions app/lib/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ def self.find_all(options={})
end

def self.find_one(id, options={})
directory = self.load_directories_with_posts(options).select { |dir| dir =~ Regexp.new("\\d\\d\\d\-#{Regexp.escape(id)}\$") }
options.merge!( {:draft => true} )
# FIXME : Refactor this mess!
return if directory.empty?
directory = directory.first
return unless directory or !File.exist?(directory)
options.merge!( {:draft => true} ) if Sinatra::Application.environment == :development
directory = self.load_directories_with_posts(options).select { |dir| dir =~ Regexp.new("\\d\\d\\d\-#{Regexp.escape(id)}(.draft)?\$") }.first
return if directory.nil? or !File.exist?(directory)
file = Dir["#{directory}/*.txt"].first
self.new( self.extract_post_info_from(file, options).merge( :comments => Marley::Comment.find_all_by_post_id(id, :conditions => { :spam => false }) ) )
end
Expand Down

0 comments on commit da2a2e7

Please sign in to comment.