Sha256: 9dd3d07fbf7c9586f2be1cae8b9126612628ba0b23aee86a2444192c26db6aac
Contents?: true
Size: 1.02 KB
Versions: 4
Compression:
Stored size: 1.02 KB
Contents
class Post < BaseClass @@id = 0 @@posts = [nil] attr_reader :id attr_accessor :title, :body, :blog_id, :published_at, :ratings_average, :author_name, :featured alias_method :featured?, :featured def initialize(attrs = {}) @id = @@id += 1 @@posts << self attrs.each_pair { |attribute, value| self.send "#{attribute}=", value } end def category_ids @category_ids ||= [] end def self.get(id) @@posts[id] end def self.get_all(ids) ids.map { |id| get(id) }.sort_by { |post| post.id } # this is so that results are not ordered by coincidence end private attr_writer :category_ids end Sunspot.setup(Post) do text :title, :body string :title integer :blog_id integer :category_ids, :multiple => true float :average_rating, :using => :ratings_average time :published_at boolean :featured, :using => :featured? string :sort_title do title.downcase.sub(/^(a|an|the)\W+/, '') if title end integer :primary_category_id do |post| post.category_ids.first end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
outoftime-sunspot-0.7.0 | spec/mocks/post.rb |
outoftime-sunspot-0.7.1 | spec/mocks/post.rb |
outoftime-sunspot-0.7.2 | spec/mocks/post.rb |
outoftime-sunspot-0.7.3 | spec/mocks/post.rb |