|
6 | 6 | # Updated:: Feb 26, 2012 |
7 | 7 | # Copyright:: 774 Copyright (c) 2012 |
8 | 8 | # License:: Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. |
9 | | -require 'active_record' |
| 9 | +require 'plugins/store/store_database' |
10 | 10 |
|
11 | 11 | module Automatic::Plugin |
12 | 12 | class Blog < ActiveRecord::Base |
13 | 13 | end |
14 | 14 |
|
15 | 15 | class StoreFullText |
| 16 | + include Automatic::Plugin::StoreDatabase |
| 17 | + |
16 | 18 | def initialize(config, pipeline=[]) |
17 | 19 | @config = config |
18 | 20 | @pipeline = pipeline |
19 | 21 | end |
20 | 22 |
|
21 | | - def create_table |
22 | | - ActiveRecord::Migration.create_table :blogs do |t| |
23 | | - t.column :title, :string |
24 | | - t.column :link, :string |
25 | | - t.column :description, :string |
26 | | - t.column :content, :string |
27 | | - t.column :created_at, :string |
28 | | - end |
| 23 | + def column_definition |
| 24 | + return { |
| 25 | + :title => :string, |
| 26 | + :link => :string, |
| 27 | + :description => :string, |
| 28 | + :content => :string, |
| 29 | + :created_at => :string, |
| 30 | + } |
| 31 | + end |
| 32 | + |
| 33 | + def unique_key |
| 34 | + return :link |
| 35 | + end |
| 36 | + |
| 37 | + def model_class |
| 38 | + return Automatic::Plugin::Blog |
29 | 39 | end |
30 | 40 |
|
31 | 41 | def run |
32 | | - ActiveRecord::Base.establish_connection( |
33 | | - :adapter => "sqlite3", |
34 | | - :database => (File.join(File.dirname(__FILE__), |
35 | | - '..', '..', 'db', @config['db']))) |
36 | | - create_table unless Blog.table_exists?() |
37 | | - blogs = Blog.find(:all) |
38 | | - return_feeds = [] |
39 | | - @pipeline.each {|feeds| |
40 | | - unless feeds.nil? |
41 | | - new_feed = false |
42 | | - feeds.items.each {|feed| |
43 | | - unless blogs.detect {|b|b.link == feed.link} |
44 | | - new_blog = Blog.new( |
45 | | - :title => feed.title, |
46 | | - :link => feed.link, |
47 | | - :description => feed.description, |
48 | | - :content => feed.content_encoded, |
49 | | - :created_at => Time.now.strftime("%Y/%m/%d %X")) |
50 | | - new_blog.save |
51 | | - new_feed = true |
52 | | - end |
53 | | - } |
54 | | - return_feeds << feeds if new_feed |
55 | | - end |
| 42 | + return for_each_new_feed { |feed| |
| 43 | + Blog.create( |
| 44 | + :title => feed.title, |
| 45 | + :link => feed.link, |
| 46 | + :description => feed.description, |
| 47 | + :content => feed.content_encoded, |
| 48 | + :created_at => Time.now.strftime("%Y/%m/%d %X")) |
56 | 49 | } |
57 | | - return_feeds |
58 | 50 | end |
59 | 51 | end |
60 | 52 | end |
0 commit comments