Class: Article

Inherits:
ActiveRecord::Base show all
Defined in:
lib/app/models/article.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Spec::Rails::Extensions::ActiveRecord::ClassMethods

#records

Methods included from Resourceful::Serialize::Model

#serialize, #to_serializable

Methods included from Spec::Rails::Extensions::ActiveRecord::InstanceMethods

#errors_on

Class Method Details

.feed_itemsObject



29
30
31
32
33
# File 'lib/app/models/article.rb', line 29

def self.feed_items
  self.find :all,
            :limit => Hubbub::Config[:items_per_feed] || 5,
            :order => 'created_at DESC'
end


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/app/models/article.rb', line 41

def self.find_by_permalink options={}
  begin
    article = self.find_all_by_title_slug(options[:slug]).detect do |article|
      time = article.created_at
      time.year == options[:year].to_i &&
      time.month == options[:month].to_i &&
      time.day == options[:day].to_i
    end
  rescue
    article = nil
  end

  article || raise(ActiveRecord::RecordNotFound)
end

.page_items(page) ⇒ Object



35
36
37
38
39
# File 'lib/app/models/article.rb', line 35

def self.page_items page
  self.paginate :order => 'created_at DESC',
                :per_page => Hubbub::Config[:items_per_page] || 10,
                :page => page
end

Instance Method Details

#tag_slugsObject



22
23
24
25
26
27
# File 'lib/app/models/article.rb', line 22

def tag_slugs
  array = self.taggings.inject([]) do |slugs, tagging|
    slugs << tagging.tag.slug
  end
  array.join ' '
end

#tag_slugs=(slugs) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/app/models/article.rb', line 14

def tag_slugs=(slugs)
  slugs.split.each do |slug|
    tag = Tag.find_or_initialize_by_slug slug
    next if self.tags.member? tag
    self.taggings.build :tag => tag, :article => self
  end
end