This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
| dcfc2d26 » | ryanb | 2008-05-08 | 1 | class Episode < ActiveRecord::Base | |
| 18ce412a » | ryanb | 2008-07-29 | 2 | has_many :comments, :dependent => :destroy | |
| 3 | has_many :taggings, :dependent => :destroy | ||||
| bf761bbc » | ryanb | 2008-06-19 | 4 | has_many :tags, :through => :taggings | |
| 18ce412a » | ryanb | 2008-07-29 | 5 | has_many :downloads, :dependent => :destroy | |
| be705e2f » | ryanb | 2008-07-20 | 6 | ||
| 8b05ccd2 » | ryanb | 2008-07-01 | 7 | acts_as_list | |
| bf761bbc » | ryanb | 2008-06-19 | 8 | ||
| ceffcd8d » | ryanb | 2008-10-19 | 9 | named_scope :published, lambda { {:conditions => ['published_at <= ?', Time.now.utc]} } | |
| 10 | named_scope :unpublished, lambda { {:conditions => ['published_at > ?', Time.now.utc]} } | ||||
| 495a36de » | ryanb | 2008-07-21 | 11 | named_scope :recent, :order => 'position DESC' | |
| 5149eab1 » | ryanb | 2008-06-19 | 12 | ||
| 97e1b940 » | ryanb | 2008-06-28 | 13 | validates_presence_of :published_at, :name | |
| be705e2f » | ryanb | 2008-07-20 | 14 | validates_associated :downloads, :on => :update # create automatically handles validation | |
| 97e1b940 » | ryanb | 2008-06-28 | 15 | ||
| 16 | before_create :set_permalink | ||||
| be705e2f » | ryanb | 2008-07-20 | 17 | after_update :save_downloads | |
| 04e4d4f6 » | ryanb | 2008-06-28 | 18 | ||
| 3146f0dc » | ryanb | 2009-04-16 | 19 | # sometimes ThinkingSphinx isn't loaded for rake tasks | |
| 20 | if respond_to? :define_index | ||||
| 21 | define_index do | ||||
| 22 | indexes :name | ||||
| 23 | indexes position, :sortable => true | ||||
| 24 | indexes description | ||||
| 25 | indexes notes | ||||
| 26 | indexes comments.content, :as => :comment_content | ||||
| 27 | indexes tags(:name), :as => :tag_names | ||||
| 7cf28d3c » | ryanb | 2008-08-18 | 28 | ||
| 3146f0dc » | ryanb | 2009-04-16 | 29 | has published_at | |
| 30 | end | ||||
| 7cf28d3c » | ryanb | 2008-08-18 | 31 | end | |
| 32 | |||||
| 33 | def self.search_published(query) | ||||
| c2f234f9 » | ryanb | 2008-08-18 | 34 | if APP_CONFIG['thinking_sphinx'] | |
| ceffcd8d » | ryanb | 2008-10-19 | 35 | search(query, :conditions => { :published_at => 0..Time.now.utc.to_i }, | |
| c2f234f9 » | ryanb | 2008-08-18 | 36 | :field_weights => { :name => 20, :description => 15, :notes => 5, :tag_names => 10 }) | |
| 36484027 » | ryanb | 2008-08-18 | 37 | else | |
| 38 | published.primitive_search(query) | ||||
| 39 | end | ||||
| 40 | rescue ThinkingSphinx::ConnectionError => e | ||||
| c2f234f9 » | ryanb | 2008-08-18 | 41 | APP_CONFIG['thinking_sphinx'] = false | |
| 36484027 » | ryanb | 2008-08-18 | 42 | raise e | |
| 7cf28d3c » | ryanb | 2008-08-18 | 43 | end | |
| 44 | |||||
| 45 | def self.primitive_search(query) | ||||
| 46 | find(:all, :conditions => primitive_search_conditions(query)) | ||||
| 47 | end | ||||
| 48 | |||||
| ae641949 » | ryanb | 2008-08-19 | 49 | def published_month | |
| 50 | published_at.beginning_of_month | ||||
| 1a513d2e » | ryanb | 2008-06-28 | 51 | end | |
| 52 | |||||
| be705e2f » | ryanb | 2008-07-20 | 53 | def mov | |
| 54 | downloads.find_by_format('mov') | ||||
| 55 | end | ||||
| 56 | |||||
| 57 | def m4v | ||||
| 58 | downloads.find_by_format('m4v') | ||||
| 59 | end | ||||
| 60 | |||||
| 5149eab1 » | ryanb | 2008-06-19 | 61 | def tag_names=(names) | |
| 6b477914 » | ryanb | 2008-06-28 | 62 | self.tags = Tag.with_names(names.split(/\s+/)) | |
| 5149eab1 » | ryanb | 2008-06-19 | 63 | end | |
| 64 | |||||
| 65 | def tag_names | ||||
| 66 | tags.map(&:name).join(' ') | ||||
| 67 | end | ||||
| 97e1b940 » | ryanb | 2008-06-28 | 68 | ||
| 69 | def to_param | ||||
| c9d6386f » | ryanb | 2009-04-16 | 70 | [position, permalink].join('-') | |
| 97e1b940 » | ryanb | 2008-06-28 | 71 | end | |
| 72 | |||||
| 7b94df03 » | ryanb | 2008-07-01 | 73 | def last_published? | |
| 8b05ccd2 » | ryanb | 2008-07-01 | 74 | self == self.class.published.last | |
| 75 | end | ||||
| 76 | |||||
| be705e2f » | ryanb | 2008-07-20 | 77 | def new_download_attributes=(download_attributes) | |
| 78 | download_attributes.each do |attributes| | ||||
| 79 | downloads.build(attributes) | ||||
| 80 | end | ||||
| 81 | end | ||||
| 82 | |||||
| 83 | def existing_download_attributes=(download_attributes) | ||||
| 84 | downloads.reject(&:new_record?).each do |download| | ||||
| 85 | attributes = download_attributes[download.id.to_s] | ||||
| 86 | if attributes | ||||
| 87 | download.attributes = attributes | ||||
| 88 | else | ||||
| 89 | downloads.delete(download) | ||||
| 90 | end | ||||
| 91 | end | ||||
| 92 | end | ||||
| 93 | |||||
| c2f4d81a » | ryanb | 2009-02-28 | 94 | def duration | |
| 95 | if seconds | ||||
| 96 | min, sec = *seconds.divmod(60) | ||||
| 97 | [min, sec.to_s.rjust(2, '0')].join(':') | ||||
| 98 | end | ||||
| 99 | end | ||||
| 100 | |||||
| 101 | def duration=(duration) | ||||
| 102 | min, sec = *duration.split(':').map(&:to_i) | ||||
| 103 | self.seconds = min*60 + sec | ||||
| 104 | end | ||||
| 105 | |||||
| 97e1b940 » | ryanb | 2008-06-28 | 106 | private | |
| 107 | |||||
| 7cf28d3c » | ryanb | 2008-08-18 | 108 | def self.primitive_search_conditions(query) | |
| 109 | query.split(/\s+/).map do |word| | ||||
| 110 | '(' + %w[name description notes].map { |col| "#{col} LIKE #{sanitize('%' + word.to_s + '%')}" }.join(' OR ') + ')' | ||||
| 111 | end.join(' AND ') | ||||
| 112 | end | ||||
| 113 | |||||
| be705e2f » | ryanb | 2008-07-20 | 114 | def save_downloads | |
| 115 | if downloads.loaded? | ||||
| 116 | downloads.each do |download| | ||||
| 117 | download.save(false) | ||||
| 118 | end | ||||
| 119 | end | ||||
| 120 | end | ||||
| 121 | |||||
| 97e1b940 » | ryanb | 2008-06-28 | 122 | def set_permalink | |
| 123 | self.permalink = name.downcase.gsub(/[^0-9a-z]+/, ' ').strip.gsub(' ', '-') if name | ||||
| 124 | end | ||||
| dcfc2d26 » | ryanb | 2008-05-08 | 125 | end | |







