pluto-models 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pluto/connecter.rb +85 -83
- data/lib/pluto/models.rb +2 -2
- data/lib/pluto/models/feed.rb +22 -9
- data/lib/pluto/models/forward.rb +0 -1
- data/lib/pluto/models/item.rb +16 -6
- data/lib/pluto/models/site.rb +26 -23
- data/lib/pluto/models/subscription.rb +1 -1
- data/lib/pluto/models/utils.rb +2 -2
- data/lib/pluto/schema.rb +153 -153
- data/lib/pluto/version.rb +2 -2
- data/test/helper.rb +0 -1
- data/test/test_filter.rb +2 -2
- data/test/test_helpers.rb +1 -1
- data/test/test_site.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad263401c798a7b1d893eb500232872a8afc0ca8
|
4
|
+
data.tar.gz: 1a49217497e1b15de32024bdc53fcef480bf0195
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11ff9b19fbe322bd20748edc5f6ce993b0235565c9501a2db45ce67d74f2655596d09a937162d1a98060d4129114cea3b03f6a685bd46d79da0270f1e5eaf889
|
7
|
+
data.tar.gz: b88a9638733715423053eeae0e81dde8d622d34c087e767ee6480c8108da1bd6b102dae3dd70c60db709abc1c94625c49f9f074bd8dbc98d5e7a6fd62c7123c2
|
data/lib/pluto/connecter.rb
CHANGED
@@ -1,83 +1,85 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Pluto
|
4
|
-
|
5
|
-
|
6
|
-
# DB Connecter / Connection Manager
|
7
|
-
# lets you establish connection
|
8
|
-
|
9
|
-
class Connecter
|
10
|
-
|
11
|
-
include LogUtils::Logging
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
# do nothing for now
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def debug=(value) @debug = value; end
|
19
|
-
def debug?() @debug || false; end
|
20
|
-
|
21
|
-
|
22
|
-
def connect( config={} )
|
23
|
-
|
24
|
-
if config.empty? # use/try DATABASE_URL from environment
|
25
|
-
|
26
|
-
logger.debug "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
|
27
|
-
|
28
|
-
db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///pluto.db' )
|
29
|
-
|
30
|
-
if db.scheme == 'postgres'
|
31
|
-
config = {
|
32
|
-
adapter: 'postgresql',
|
33
|
-
host: db.host,
|
34
|
-
port: db.port,
|
35
|
-
username: db.user,
|
36
|
-
password: db.password,
|
37
|
-
database: db.path[1..-1],
|
38
|
-
encoding: 'utf8'
|
39
|
-
}
|
40
|
-
else # assume sqlite3
|
41
|
-
config = {
|
42
|
-
adapter: db.scheme, # sqlite3
|
43
|
-
database: db.path[1..-1] # pluto.db (NB: cut off leading /, thus 1..-1)
|
44
|
-
}
|
45
|
-
end
|
46
|
-
end # if config.nil?
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
### for dbbrowser and other tools add to ActiveRecord
|
52
|
-
|
53
|
-
if ActiveRecord::Base.configurations.nil? # todo/check: can this ever happen? remove?
|
54
|
-
|
55
|
-
ActiveRecord::Base.configurations = {} # make it an empty hash
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end #
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Pluto
|
4
|
+
|
5
|
+
|
6
|
+
# DB Connecter / Connection Manager
|
7
|
+
# lets you establish connection
|
8
|
+
|
9
|
+
class Connecter
|
10
|
+
|
11
|
+
include LogUtils::Logging
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
# do nothing for now
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def debug=(value) @debug = value; end
|
19
|
+
def debug?() @debug || false; end
|
20
|
+
|
21
|
+
|
22
|
+
def connect( config={} )
|
23
|
+
|
24
|
+
if config.empty? # use/try DATABASE_URL from environment
|
25
|
+
|
26
|
+
logger.debug "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"
|
27
|
+
|
28
|
+
db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///pluto.db' )
|
29
|
+
|
30
|
+
if db.scheme == 'postgres'
|
31
|
+
config = {
|
32
|
+
adapter: 'postgresql',
|
33
|
+
host: db.host,
|
34
|
+
port: db.port,
|
35
|
+
username: db.user,
|
36
|
+
password: db.password,
|
37
|
+
database: db.path[1..-1],
|
38
|
+
encoding: 'utf8'
|
39
|
+
}
|
40
|
+
else # assume sqlite3
|
41
|
+
config = {
|
42
|
+
adapter: db.scheme, # sqlite3
|
43
|
+
database: db.path[1..-1] # pluto.db (NB: cut off leading /, thus 1..-1)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end # if config.nil?
|
47
|
+
|
48
|
+
logger.info 'db settings:'
|
49
|
+
logger.info config.pretty_inspect
|
50
|
+
|
51
|
+
### for dbbrowser and other tools add to ActiveRecord
|
52
|
+
|
53
|
+
if ActiveRecord::Base.configurations.nil? # todo/check: can this ever happen? remove?
|
54
|
+
logger.debug "ActiveRecord configurations nil - set to empty hash"
|
55
|
+
ActiveRecord::Base.configurations = {} # make it an empty hash
|
56
|
+
end
|
57
|
+
|
58
|
+
## todo/fix: remove debug? option - why? why not?
|
59
|
+
## (just) use logger level eg. logger.debug
|
60
|
+
if debug?
|
61
|
+
logger.debug 'ar configurations (before):'
|
62
|
+
logger.debug ActiveRecord::Base.configurations.pretty_inspect
|
63
|
+
end
|
64
|
+
|
65
|
+
# note: for now always use pluto key for config storage
|
66
|
+
ActiveRecord::Base.configurations['pluto'] = config
|
67
|
+
|
68
|
+
if debug?
|
69
|
+
logger.debug 'ar configurations (after):'
|
70
|
+
logger.debug ActiveRecord::Base.configurations.pretty_inspect
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
# for debugging - disable for production use
|
75
|
+
if debug?
|
76
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
77
|
+
end
|
78
|
+
|
79
|
+
ActiveRecord::Base.establish_connection( config )
|
80
|
+
end # method connect
|
81
|
+
|
82
|
+
|
83
|
+
end # class Connecter
|
84
|
+
|
85
|
+
end # module Pluto
|
data/lib/pluto/models.rb
CHANGED
@@ -78,7 +78,7 @@ module Pluto
|
|
78
78
|
|
79
79
|
unless Model::Feed.table_exists?
|
80
80
|
Pluto.create
|
81
|
-
end
|
81
|
+
end
|
82
82
|
end # method auto_migrate!
|
83
83
|
|
84
84
|
|
@@ -111,4 +111,4 @@ end # module Pluto
|
|
111
111
|
|
112
112
|
|
113
113
|
# say hello
|
114
|
-
puts Pluto.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
|
114
|
+
puts Pluto.banner if $DEBUG || (defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG)
|
data/lib/pluto/models/feed.rb
CHANGED
@@ -4,7 +4,19 @@
|
|
4
4
|
module Pluto
|
5
5
|
module Model
|
6
6
|
|
7
|
+
|
7
8
|
class Feed < ActiveRecord::Base
|
9
|
+
|
10
|
+
## logging w/ ActiveRecord
|
11
|
+
## todo/check: check if logger instance method is present by default?
|
12
|
+
## only class method present?
|
13
|
+
## what's the best way to add logging to activerecord (use "builtin" machinery??)
|
14
|
+
|
15
|
+
def debug=(value) @debug = value; end
|
16
|
+
def debug?() @debug || false; end
|
17
|
+
|
18
|
+
|
19
|
+
|
8
20
|
self.table_name = 'feeds'
|
9
21
|
|
10
22
|
has_many :items
|
@@ -72,12 +84,11 @@ class Feed < ActiveRecord::Base
|
|
72
84
|
end
|
73
85
|
|
74
86
|
|
75
|
-
def debug=(value) @debug = value; end
|
76
|
-
def debug?() @debug || false; end
|
77
|
-
|
78
87
|
|
79
88
|
def deep_update_from_struct!( data )
|
80
89
|
|
90
|
+
logger = LogUtils::Logger.root
|
91
|
+
|
81
92
|
######
|
82
93
|
## check for filters (includes/excludes) if present
|
83
94
|
## for now just check for includes
|
@@ -90,18 +101,18 @@ class Feed < ActiveRecord::Base
|
|
90
101
|
|
91
102
|
data.items.each do |item|
|
92
103
|
if includesFilter && includesFilter.match_item?( item ) == false
|
93
|
-
|
94
|
-
|
104
|
+
logger.info "** SKIPPING | #{item.title}"
|
105
|
+
logger.info " no include terms match: #{includes}"
|
95
106
|
next ## skip to next item
|
96
107
|
end
|
97
108
|
|
98
109
|
item_rec = Item.find_by_guid( item.guid )
|
99
110
|
if item_rec.nil?
|
100
111
|
item_rec = Item.new
|
101
|
-
|
112
|
+
logger.info "** NEW | #{item.title}"
|
102
113
|
else
|
103
114
|
## todo: check if any attribs changed
|
104
|
-
|
115
|
+
logger.info "UPDATE | #{item.title}"
|
105
116
|
end
|
106
117
|
|
107
118
|
item_rec.debug = debug? ? true : false # pass along debug flag
|
@@ -133,6 +144,8 @@ class Feed < ActiveRecord::Base
|
|
133
144
|
|
134
145
|
def update_from_struct!( data )
|
135
146
|
|
147
|
+
logger = LogUtils::Logger.root
|
148
|
+
|
136
149
|
##
|
137
150
|
# todo:
|
138
151
|
## strip all tags from summary (subtitle)
|
@@ -158,9 +171,9 @@ class Feed < ActiveRecord::Base
|
|
158
171
|
if debug?
|
159
172
|
## puts "*** dump feed_attribs:"
|
160
173
|
## pp feed_attribs
|
161
|
-
|
174
|
+
logger.debug "*** dump feed_attribs w/ class types:"
|
162
175
|
feed_attribs.each do |key,value|
|
163
|
-
|
176
|
+
logger.debug " #{key}: >#{value}< : #{value.class.name}"
|
164
177
|
end
|
165
178
|
end
|
166
179
|
|
data/lib/pluto/models/forward.rb
CHANGED
data/lib/pluto/models/item.rb
CHANGED
@@ -4,12 +4,22 @@ module Pluto
|
|
4
4
|
module Model
|
5
5
|
|
6
6
|
class Item < ActiveRecord::Base
|
7
|
+
|
8
|
+
## logging w/ ActiveRecord
|
9
|
+
## todo/check: check if logger instance method is present by default?
|
10
|
+
## only class method present?
|
11
|
+
## what's the best way to add logging to activerecord (use "builtin" machinery??)
|
12
|
+
|
13
|
+
def debug=(value) @debug = value; end
|
14
|
+
def debug?() @debug || false; end
|
15
|
+
|
16
|
+
|
7
17
|
self.table_name = 'items'
|
8
18
|
|
9
19
|
belongs_to :feed
|
10
20
|
|
11
21
|
## todo/fix:
|
12
|
-
## use a module ref or something; do NOT include all methods - why? why not?
|
22
|
+
## use a module ref or something; do NOT include all methods - why? why not?
|
13
23
|
include TextUtils::HypertextHelper ## e.g. lets us use strip_tags( ht )
|
14
24
|
include FeedFilter::AdsFilter ## e.g. lets us use strip_ads( ht )
|
15
25
|
|
@@ -46,11 +56,11 @@ class Item < ActiveRecord::Base
|
|
46
56
|
end
|
47
57
|
|
48
58
|
|
49
|
-
def debug=(value) @debug = value; end
|
50
|
-
def debug?() @debug || false; end
|
51
|
-
|
52
59
|
|
53
60
|
def update_from_struct!( data )
|
61
|
+
|
62
|
+
logger = LogUtils::Logger.root
|
63
|
+
|
54
64
|
## check: new item/record? not saved? add guid
|
55
65
|
# otherwise do not add guid - why? why not?
|
56
66
|
|
@@ -68,10 +78,10 @@ class Item < ActiveRecord::Base
|
|
68
78
|
}
|
69
79
|
|
70
80
|
if debug?
|
71
|
-
|
81
|
+
logger.debug "*** dump item_attribs w/ class types:"
|
72
82
|
item_attribs.each do |key,value|
|
73
83
|
next if [:summary,:content].include?( key ) # skip summary n content
|
74
|
-
|
84
|
+
logger.debug " #{key}: >#{value}< : #{value.class.name}"
|
75
85
|
end
|
76
86
|
end
|
77
87
|
|
data/lib/pluto/models/site.rb
CHANGED
@@ -4,15 +4,18 @@ module Pluto
|
|
4
4
|
module Model
|
5
5
|
|
6
6
|
class Site < ActiveRecord::Base
|
7
|
+
|
8
|
+
|
9
|
+
|
7
10
|
self.table_name = 'sites'
|
8
|
-
|
11
|
+
|
9
12
|
has_many :subscriptions
|
10
13
|
has_many :feeds, :through => :subscriptions
|
11
14
|
has_many :items, :through => :feeds
|
12
15
|
|
13
16
|
##################################
|
14
17
|
# attribute reader aliases
|
15
|
-
def name() title;
|
18
|
+
def name() title; end # alias for title
|
16
19
|
|
17
20
|
def owner_name() author; end # alias for author
|
18
21
|
def owner() author; end # alias(2) for author
|
@@ -46,6 +49,8 @@ class Site < ActiveRecord::Base
|
|
46
49
|
|
47
50
|
def deep_update_from_hash!( config, opts={} )
|
48
51
|
|
52
|
+
logger = LogUtils::Logger.root
|
53
|
+
|
49
54
|
site_attribs = {
|
50
55
|
title: config['title'] || config['name'], # support either title or name
|
51
56
|
url: config['source'] || config['url'], # support source or url for source url for auto-update (optional)
|
@@ -59,7 +64,6 @@ class Site < ActiveRecord::Base
|
|
59
64
|
site_attribs[:key] = site_key if site_key
|
60
65
|
|
61
66
|
|
62
|
-
logger = LogUtils::Logger.root
|
63
67
|
logger.debug "site_attribs: #{site_attribs.inspect}"
|
64
68
|
|
65
69
|
if new_record?
|
@@ -67,7 +71,7 @@ class Site < ActiveRecord::Base
|
|
67
71
|
## change - model/table/schema!!!
|
68
72
|
Activity.create!( text: "new site >#{key}< - #{title}" )
|
69
73
|
end
|
70
|
-
|
74
|
+
|
71
75
|
update_attributes!( site_attribs )
|
72
76
|
|
73
77
|
|
@@ -135,41 +139,41 @@ class Site < ActiveRecord::Base
|
|
135
139
|
##
|
136
140
|
# auto-fill; convenience helpers
|
137
141
|
|
138
|
-
|
142
|
+
if feed_hash['meetup']
|
139
143
|
## link/url = http://www.meetup.com/vienna-rb
|
140
144
|
## feed/feed_url = http://www.meetup.com/vienna-rb/events/rss/vienna.rb/
|
141
145
|
|
142
|
-
|
143
|
-
|
144
|
-
|
146
|
+
feed_attribs[:url] = "http://www.meetup.com/#{feed_hash['meetup']}" if feed_attribs[:url].nil?
|
147
|
+
feed_attribs[:feed_url] = "http://www.meetup.com/#{feed_hash['meetup']}/events/rss/#{feed_hash['meetup']}/" if feed_attribs[:feed_url].nil?
|
148
|
+
end
|
145
149
|
|
146
|
-
|
150
|
+
if feed_hash['googlegroups']
|
147
151
|
## link/url = https://groups.google.com/group/beerdb or
|
148
152
|
## https://groups.google.com/forum/#!forum/beerdb
|
149
153
|
## feed/feed_url = https://groups.google.com/forum/feed/beerdb/topics/atom.xml?num=15
|
150
154
|
|
151
|
-
|
152
|
-
|
153
|
-
|
155
|
+
feed_attribs[:url] = "https://groups.google.com/group/#{feed_hash['googlegroups']}" if feed_attribs[:url].nil?
|
156
|
+
feed_attribs[:feed_url] = "https://groups.google.com/forum/feed//#{feed_hash['googlegroups']}/topics/atom.xml?num=15" if feed_attribs[:feed_url].nil?
|
157
|
+
end
|
154
158
|
|
155
|
-
|
159
|
+
if feed_hash['github'] && feed_hash['github'].index('/') ## e.g. jekyll/jekyll
|
156
160
|
## link/url = https://github.com/jekyll/jekyll
|
157
161
|
## feed/feed_url = https://github.com/jekyll/jekyll/commits/master.atom
|
158
162
|
|
159
|
-
|
160
|
-
|
161
|
-
|
163
|
+
feed_attribs[:url] = "https://github.com/#{feed_hash['github']}" if feed_attribs[:url].nil?
|
164
|
+
feed_attribs[:feed_url] = "https://github.com/#{feed_hash['github']}/commits/master.atom" if feed_attribs[:feed_url].nil?
|
165
|
+
end
|
162
166
|
|
163
|
-
|
167
|
+
if feed_hash['rubygems'] && feed_attribs[:url].nil? && feed_attribs[:feed_url].nil?
|
164
168
|
## link/url = http://rubygems.org/gems/jekyll
|
165
169
|
## feed/feed_url = http://rubygems.org/gems/jekyll/versions.atom
|
166
170
|
|
167
|
-
|
168
|
-
|
169
|
-
|
171
|
+
feed_attribs[:url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}" if feed_attribs[:url].nil?
|
172
|
+
feed_attribs[:feed_url] = "http://rubygems.org/gems/#{feed_hash['rubygems']}/versions.atom" if feed_attribs[:feed_url].nil?
|
173
|
+
end
|
170
174
|
|
171
175
|
|
172
|
-
|
176
|
+
logger.info "Updating feed subscription >#{feed_key}< - >#{feed_attribs[:feed_url]}<..."
|
173
177
|
|
174
178
|
feed_rec = Feed.find_by_key( feed_key )
|
175
179
|
if feed_rec.nil?
|
@@ -186,7 +190,7 @@ class Site < ActiveRecord::Base
|
|
186
190
|
|
187
191
|
# add subscription record
|
188
192
|
# note: subscriptions get cleaned out on update first (see above)
|
189
|
-
subscriptions.create!( feed_id: feed_rec.id )
|
193
|
+
subscriptions.create!( feed_id: feed_rec.id )
|
190
194
|
end
|
191
195
|
|
192
196
|
end # method deep_update_from_hash!
|
@@ -196,4 +200,3 @@ end # class Site
|
|
196
200
|
|
197
201
|
end # module Model
|
198
202
|
end # module Pluto
|
199
|
-
|
data/lib/pluto/models/utils.rb
CHANGED
@@ -29,7 +29,7 @@ class ItemCursor
|
|
29
29
|
# new date also **always** starts new feed
|
30
30
|
# - e.g. used for grouping within day (follows planet planet convention)
|
31
31
|
|
32
|
-
if new_date || last_feed_id != item.feed.id
|
32
|
+
if new_date || last_feed_id != item.feed.id
|
33
33
|
new_feed = true
|
34
34
|
else
|
35
35
|
new_feed = false
|
@@ -41,7 +41,7 @@ class ItemCursor
|
|
41
41
|
last_feed_id = item.feed.id
|
42
42
|
end
|
43
43
|
end # method each
|
44
|
-
|
44
|
+
|
45
45
|
end # class ItemCursor
|
46
46
|
|
47
47
|
|
data/lib/pluto/schema.rb
CHANGED
@@ -1,153 +1,153 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Pluto
|
4
|
-
|
5
|
-
class CreateDb
|
6
|
-
|
7
|
-
def up
|
8
|
-
|
9
|
-
ActiveRecord::Schema.define do
|
10
|
-
create_table :sites do |t|
|
11
|
-
t.string :key, null: false # e.g. ruby, js, etc.
|
12
|
-
t.string :title, null: false # e.g Planet Ruby, Planet JavaScript, etc.
|
13
|
-
|
14
|
-
t.string :author # owner_name, author_name
|
15
|
-
t.string :email # owner_email, author_email
|
16
|
-
t.datetime :updated # date for subscription list last updated via pluto
|
17
|
-
|
18
|
-
############
|
19
|
-
# filters (site-wide)
|
20
|
-
t.string :includes # regex
|
21
|
-
t.string :excludes # regex
|
22
|
-
|
23
|
-
|
24
|
-
######################
|
25
|
-
# for auto-update of feed list/site config
|
26
|
-
|
27
|
-
t.string :url # source url for auto-update (optional)
|
28
|
-
|
29
|
-
## note: make sure to use same fields for update check as feed
|
30
|
-
|
31
|
-
t.datetime :fetched # date for last fetched/checked for feeds via pluto -- make not null ??
|
32
|
-
t.integer :http_code # last http status code e.g. 200,404,etc.
|
33
|
-
t.string :http_etag # last http header etag
|
34
|
-
## note: save last-modified header as text (not datetime) - pass through as is
|
35
|
-
t.string :http_last_modified # last http header last-modified - note: save header as plain text!!! pass along in next request as-is
|
36
|
-
t.string :http_server # last http server header if present
|
37
|
-
|
38
|
-
# note: do NOT store body content (that is, text) and md5 digest
|
39
|
-
# use git! and github! commit will be http_etag!!
|
40
|
-
t.string :md5 # md5 hash of body
|
41
|
-
|
42
|
-
|
43
|
-
#############
|
44
|
-
# more fields
|
45
|
-
|
46
|
-
t.timestamps # created_at, updated_at
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
create_table :subscriptions do |t| # has_many join table (sites/feeds)
|
51
|
-
t.references :site, null: false
|
52
|
-
t.references :feed, null: false
|
53
|
-
t.timestamps
|
54
|
-
end
|
55
|
-
|
56
|
-
create_table :feeds do |t|
|
57
|
-
t.string :key, null: false
|
58
|
-
t.string :encoding, null: false, default: 'utf8' # charset encoding; default to utf8
|
59
|
-
t.string :format # e.g. atom (1.0), rss 2.0, etc.
|
60
|
-
|
61
|
-
t.string :title # user supplied title
|
62
|
-
t.string :url # user supplied site url
|
63
|
-
t.string :feed_url # user supplied feed url
|
64
|
-
|
65
|
-
t.string :auto_title # "fallback" - auto(fill) title from feed
|
66
|
-
t.string :auto_url # "fallback" - auto(fill) url from feed
|
67
|
-
t.string :auto_feed_url # "fallback" - auto discovery feed url from (site) url
|
68
|
-
|
69
|
-
t.text :summary # e.g. description (rss), subtitle (atom)
|
70
|
-
## todo: add auto_summary - why? why not?
|
71
|
-
|
72
|
-
t.string :generator # feed generator (e.g. wordpress, etc.) from feed
|
73
|
-
|
74
|
-
t.datetime :updated # from feed updated(atom) + lastBuildDate(rss)
|
75
|
-
t.datetime :published # from feed published(atom) + pubDate(rss) - note: published basically an alias for created
|
76
|
-
|
77
|
-
|
78
|
-
### extras (move to array for custom fields or similar??)
|
79
|
-
t.string :author # author_name, owner_name
|
80
|
-
t.string :email # author_email, owner_email
|
81
|
-
t.string :avatar # gravator or hackergotchi handle (optional)
|
82
|
-
t.string :location # e.g. Vienna > Austria, Bamberg > Germany etc. (optional)
|
83
|
-
|
84
|
-
t.string :github # github handle (optional)
|
85
|
-
t.string :rubygems # rubygems handle (optional)
|
86
|
-
t.string :twitter # twitter handle (optional)
|
87
|
-
t.string :meetup # meetup handle (optional)
|
88
|
-
|
89
|
-
|
90
|
-
### add class/kind field e.g.
|
91
|
-
# - personal feed/blog/site, that is, individual author
|
92
|
-
# - team blog/site
|
93
|
-
# - org (anization) or com(pany blog/site)
|
94
|
-
# - newsfeed (composite)
|
95
|
-
# - other (link blog?, podcast?) - why? why not??
|
96
|
-
|
97
|
-
############
|
98
|
-
# filters (feed-wide)
|
99
|
-
t.string :includes # regex
|
100
|
-
t.string :excludes # regex
|
101
|
-
# todo: add generic filter list e.g. t.string :filters (comma,pipe or space separated method names?)
|
102
|
-
|
103
|
-
# -- our own (meta) fields
|
104
|
-
t.datetime :items_last_updated # cache last (latest) updated for items - e.g. latest date from updated item
|
105
|
-
t.datetime :fetched # last fetched date via pluto
|
106
|
-
|
107
|
-
t.integer :http_code # last http status code e.g. 200,404,etc.
|
108
|
-
t.string :http_etag # last http header etag
|
109
|
-
## note: save last-modified header as text (not datetime) - pass through as is
|
110
|
-
t.string :http_last_modified # last http header last-modified - note: save header as plain text!!! pass along in next request as-is
|
111
|
-
t.string :http_server # last http server header if present
|
112
|
-
|
113
|
-
t.string :md5 # md5 hash of body
|
114
|
-
t.text :body # last http response body (complete feed!)
|
115
|
-
|
116
|
-
|
117
|
-
t.timestamps # created_at, updated_at
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
create_table :items do |t|
|
122
|
-
t.string :guid
|
123
|
-
t.string :url
|
124
|
-
|
125
|
-
## note: title may contain more than 255 chars!!
|
126
|
-
## e.g. Rails Girls blog has massive titles in feed
|
127
|
-
## cut-off/limit to 255 - why?? why not??
|
128
|
-
## also strip tags in titles - why? why not?? - see feed.title2/auto_title2
|
129
|
-
|
130
|
-
t.text :title # todo: add some :null => false ??
|
131
|
-
t.text :summary # e.g. description (rss), summary (atom)
|
132
|
-
t.text :content
|
133
|
-
|
134
|
-
t.datetime :updated # from feed updated (atom) + pubDate(rss)
|
135
|
-
t.datetime :published # from feed published (atom) -- note: published is basically an alias for created
|
136
|
-
|
137
|
-
## todo: add :last_updated_at ?? (NOTE: updated_at already take by auto-timestamps)
|
138
|
-
t.references :feed, null: false
|
139
|
-
|
140
|
-
t.datetime :fetched # last fetched/check date via pluto
|
141
|
-
t.timestamps # created_at, updated_at
|
142
|
-
|
143
|
-
## t.string :author
|
144
|
-
## todo: add author/authors, category/categories
|
145
|
-
end
|
146
|
-
|
147
|
-
end # block Schema.define
|
148
|
-
|
149
|
-
end # method up
|
150
|
-
|
151
|
-
end # class CreateDb
|
152
|
-
|
153
|
-
end # module Pluto
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Pluto
|
4
|
+
|
5
|
+
class CreateDb
|
6
|
+
|
7
|
+
def up
|
8
|
+
|
9
|
+
ActiveRecord::Schema.define do
|
10
|
+
create_table :sites do |t|
|
11
|
+
t.string :key, null: false # e.g. ruby, js, etc.
|
12
|
+
t.string :title, null: false # e.g Planet Ruby, Planet JavaScript, etc.
|
13
|
+
|
14
|
+
t.string :author # owner_name, author_name
|
15
|
+
t.string :email # owner_email, author_email
|
16
|
+
t.datetime :updated # date for subscription list last updated via pluto
|
17
|
+
|
18
|
+
############
|
19
|
+
# filters (site-wide)
|
20
|
+
t.string :includes # regex
|
21
|
+
t.string :excludes # regex
|
22
|
+
|
23
|
+
|
24
|
+
######################
|
25
|
+
# for auto-update of feed list/site config
|
26
|
+
|
27
|
+
t.string :url # source url for auto-update (optional)
|
28
|
+
|
29
|
+
## note: make sure to use same fields for update check as feed
|
30
|
+
|
31
|
+
t.datetime :fetched # date for last fetched/checked for feeds via pluto -- make not null ??
|
32
|
+
t.integer :http_code # last http status code e.g. 200,404,etc.
|
33
|
+
t.string :http_etag # last http header etag
|
34
|
+
## note: save last-modified header as text (not datetime) - pass through as is
|
35
|
+
t.string :http_last_modified # last http header last-modified - note: save header as plain text!!! pass along in next request as-is
|
36
|
+
t.string :http_server # last http server header if present
|
37
|
+
|
38
|
+
# note: do NOT store body content (that is, text) and md5 digest
|
39
|
+
# use git! and github! commit will be http_etag!!
|
40
|
+
t.string :md5 # md5 hash of body
|
41
|
+
|
42
|
+
|
43
|
+
#############
|
44
|
+
# more fields
|
45
|
+
|
46
|
+
t.timestamps # created_at, updated_at
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
create_table :subscriptions do |t| # has_many join table (sites/feeds)
|
51
|
+
t.references :site, null: false
|
52
|
+
t.references :feed, null: false
|
53
|
+
t.timestamps
|
54
|
+
end
|
55
|
+
|
56
|
+
create_table :feeds do |t|
|
57
|
+
t.string :key, null: false
|
58
|
+
t.string :encoding, null: false, default: 'utf8' # charset encoding; default to utf8
|
59
|
+
t.string :format # e.g. atom (1.0), rss 2.0, etc.
|
60
|
+
|
61
|
+
t.string :title # user supplied title
|
62
|
+
t.string :url # user supplied site url
|
63
|
+
t.string :feed_url # user supplied feed url
|
64
|
+
|
65
|
+
t.string :auto_title # "fallback" - auto(fill) title from feed
|
66
|
+
t.string :auto_url # "fallback" - auto(fill) url from feed
|
67
|
+
t.string :auto_feed_url # "fallback" - auto discovery feed url from (site) url
|
68
|
+
|
69
|
+
t.text :summary # e.g. description (rss), subtitle (atom)
|
70
|
+
## todo: add auto_summary - why? why not?
|
71
|
+
|
72
|
+
t.string :generator # feed generator (e.g. wordpress, etc.) from feed
|
73
|
+
|
74
|
+
t.datetime :updated # from feed updated(atom) + lastBuildDate(rss)
|
75
|
+
t.datetime :published # from feed published(atom) + pubDate(rss) - note: published basically an alias for created
|
76
|
+
|
77
|
+
|
78
|
+
### extras (move to array for custom fields or similar??)
|
79
|
+
t.string :author # author_name, owner_name
|
80
|
+
t.string :email # author_email, owner_email
|
81
|
+
t.string :avatar # gravator or hackergotchi handle (optional)
|
82
|
+
t.string :location # e.g. Vienna > Austria, Bamberg > Germany etc. (optional)
|
83
|
+
|
84
|
+
t.string :github # github handle (optional)
|
85
|
+
t.string :rubygems # rubygems handle (optional)
|
86
|
+
t.string :twitter # twitter handle (optional)
|
87
|
+
t.string :meetup # meetup handle (optional)
|
88
|
+
|
89
|
+
|
90
|
+
### add class/kind field e.g.
|
91
|
+
# - personal feed/blog/site, that is, individual author
|
92
|
+
# - team blog/site
|
93
|
+
# - org (anization) or com(pany blog/site)
|
94
|
+
# - newsfeed (composite)
|
95
|
+
# - other (link blog?, podcast?) - why? why not??
|
96
|
+
|
97
|
+
############
|
98
|
+
# filters (feed-wide)
|
99
|
+
t.string :includes # regex
|
100
|
+
t.string :excludes # regex
|
101
|
+
# todo: add generic filter list e.g. t.string :filters (comma,pipe or space separated method names?)
|
102
|
+
|
103
|
+
# -- our own (meta) fields
|
104
|
+
t.datetime :items_last_updated # cache last (latest) updated for items - e.g. latest date from updated item
|
105
|
+
t.datetime :fetched # last fetched date via pluto
|
106
|
+
|
107
|
+
t.integer :http_code # last http status code e.g. 200,404,etc.
|
108
|
+
t.string :http_etag # last http header etag
|
109
|
+
## note: save last-modified header as text (not datetime) - pass through as is
|
110
|
+
t.string :http_last_modified # last http header last-modified - note: save header as plain text!!! pass along in next request as-is
|
111
|
+
t.string :http_server # last http server header if present
|
112
|
+
|
113
|
+
t.string :md5 # md5 hash of body
|
114
|
+
t.text :body # last http response body (complete feed!)
|
115
|
+
|
116
|
+
|
117
|
+
t.timestamps # created_at, updated_at
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
create_table :items do |t|
|
122
|
+
t.string :guid
|
123
|
+
t.string :url
|
124
|
+
|
125
|
+
## note: title may contain more than 255 chars!!
|
126
|
+
## e.g. Rails Girls blog has massive titles in feed
|
127
|
+
## cut-off/limit to 255 - why?? why not??
|
128
|
+
## also strip tags in titles - why? why not?? - see feed.title2/auto_title2
|
129
|
+
|
130
|
+
t.text :title # todo: add some :null => false ??
|
131
|
+
t.text :summary # e.g. description (rss), summary (atom)
|
132
|
+
t.text :content
|
133
|
+
|
134
|
+
t.datetime :updated # from feed updated (atom) + pubDate(rss)
|
135
|
+
t.datetime :published # from feed published (atom) -- note: published is basically an alias for created
|
136
|
+
|
137
|
+
## todo: add :last_updated_at ?? (NOTE: updated_at already take by auto-timestamps)
|
138
|
+
t.references :feed, null: false
|
139
|
+
|
140
|
+
t.datetime :fetched # last fetched/check date via pluto
|
141
|
+
t.timestamps # created_at, updated_at
|
142
|
+
|
143
|
+
## t.string :author
|
144
|
+
## todo: add author/authors, category/categories
|
145
|
+
end
|
146
|
+
|
147
|
+
end # block Schema.define
|
148
|
+
|
149
|
+
end # method up
|
150
|
+
|
151
|
+
end # class CreateDb
|
152
|
+
|
153
|
+
end # module Pluto
|
data/lib/pluto/version.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/test_filter.rb
CHANGED
@@ -11,7 +11,7 @@ require 'helper'
|
|
11
11
|
class TestFilter < MiniTest::Test
|
12
12
|
|
13
13
|
def test_includes
|
14
|
-
|
14
|
+
|
15
15
|
feed1 = Feed.create!(
|
16
16
|
key: 'test',
|
17
17
|
title: 'Test',
|
@@ -26,7 +26,7 @@ class TestFilter < MiniTest::Test
|
|
26
26
|
feed_data = FeedParser::Feed.new
|
27
27
|
feed_data.title = 'Test'
|
28
28
|
feed_data.items = []
|
29
|
-
|
29
|
+
|
30
30
|
item_data = FeedParser::Item.new
|
31
31
|
item_data.title = 'Test #1'
|
32
32
|
item_data.summary = 'Test'
|
data/test/test_helpers.rb
CHANGED
data/test/test_site.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluto-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|