pluto-models 1.5.6 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +6 -5
- data/lib/pluto/models.rb +3 -1
- data/lib/pluto/models/feed.rb +35 -14
- data/lib/pluto/models/item.rb +29 -7
- data/lib/pluto/version.rb +2 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad742c8fd3f916716ace3acb90d1c1a7371b77e
|
4
|
+
data.tar.gz: fc7a5f6e1b85585b9efb2c34848b04274f80f528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17db570f9d9987f8aa6fdc5addeca4eebad1d4a9aeef59b244a2dd8c7e7c25f3bf13018290b300583ea50c08d069ea591894de8367ad441e3907a0c679cdf233
|
7
|
+
data.tar.gz: 870555443a637ee053c2eeb164998f35f8007cce25930c948bae3615f9d7948fcd6712a9b0a12459f369b97ba45a8ef2f1e93bc155586aa323586d78a949a8a3
|
data/Rakefile
CHANGED
@@ -18,11 +18,12 @@ Hoe.spec 'pluto-models' do
|
|
18
18
|
self.history_file = 'CHANGELOG.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
-
['props',
|
22
|
-
['logutils',
|
23
|
-
['feedparser',
|
24
|
-
['feedfilter',
|
25
|
-
['
|
21
|
+
['props', '>= 1.2.0'],
|
22
|
+
['logutils', '>= 0.6.1'],
|
23
|
+
['feedparser', '>= 2.1.2'],
|
24
|
+
['feedfilter', '>= 1.1.1'],
|
25
|
+
['date-formatter', '>= 0.1.1'],
|
26
|
+
['textutils', '>= 1.4.0'],
|
26
27
|
['activerecord'],
|
27
28
|
['logutils-activerecord', '>= 0.2.1'],
|
28
29
|
['props-activerecord', '>= 0.2.0'],
|
data/lib/pluto/models.rb
CHANGED
@@ -8,6 +8,7 @@ require 'uri'
|
|
8
8
|
require 'pp'
|
9
9
|
require 'fileutils'
|
10
10
|
require 'date'
|
11
|
+
require 'time'
|
11
12
|
require 'digest/md5'
|
12
13
|
|
13
14
|
require 'logger' # Note: use for ActiveRecord::Base.logger = Logger.new( STDOUT ) for now
|
@@ -22,6 +23,7 @@ require 'logutils'
|
|
22
23
|
require 'textutils'
|
23
24
|
require 'feedparser'
|
24
25
|
require 'feedfilter'
|
26
|
+
require 'date/formatter'
|
25
27
|
|
26
28
|
|
27
29
|
## add more activerecords addons/utils
|
@@ -110,7 +112,7 @@ module Pluto
|
|
110
112
|
#########################################
|
111
113
|
## let's put test configuration in its own namespace / module
|
112
114
|
class Test ## todo/check: works with module too? use a module - why? why not?
|
113
|
-
|
115
|
+
|
114
116
|
####
|
115
117
|
# todo/fix: find a better way to configure shared test datasets - why? why not?
|
116
118
|
# note: use one-up (..) directory for now as default - why? why not?
|
data/lib/pluto/models/feed.rb
CHANGED
@@ -41,7 +41,7 @@ class Feed < ActiveRecord::Base
|
|
41
41
|
##################################
|
42
42
|
# attribute reader aliases
|
43
43
|
#
|
44
|
-
# note: CANNOT use alias_method :name, :title
|
44
|
+
# note: CANNOT use alias_method :name, :title
|
45
45
|
# will NOT work for non-existing/on-demand-generated methods in activerecord
|
46
46
|
#
|
47
47
|
# use rails alias_attribute :new, :old (incl. reader/predicate/writer)
|
@@ -60,7 +60,7 @@ class Feed < ActiveRecord::Base
|
|
60
60
|
alias_attr_reader :author_email, :email # alias for email
|
61
61
|
alias_attr_reader :author_email, :email # alias(2) for email
|
62
62
|
|
63
|
-
|
63
|
+
|
64
64
|
#################
|
65
65
|
## attributes with fallbacks or (auto-)backups - use feed.data.<attribute> for "raw" / "original" access
|
66
66
|
def url() read_attribute_w_fallbacks( :url, :auto_url ); end
|
@@ -70,37 +70,58 @@ class Feed < ActiveRecord::Base
|
|
70
70
|
def url?() url.present?; end
|
71
71
|
def title?() title.present?; end
|
72
72
|
def feed_url?() feed_url.present?; end
|
73
|
-
|
73
|
+
|
74
74
|
## note:
|
75
75
|
## only use fallback for updated, that is, updated (or published)
|
76
|
-
## do NOT use fallback for published / created -- why? why not
|
76
|
+
## ~~do NOT use fallback for published / created -- why? why not?~~
|
77
77
|
## add items_last_updated to updated as last fall back - why? why not?
|
78
|
-
def updated() read_attribute_w_fallbacks( :updated,
|
78
|
+
def updated() read_attribute_w_fallbacks( :updated, :published ); end
|
79
|
+
def published() read_attribute_w_fallbacks( :published, :updated, ); end
|
80
|
+
|
79
81
|
def updated?() updated.present?; end
|
80
|
-
|
82
|
+
def published?() published.present?; end
|
83
|
+
|
84
|
+
#############
|
85
|
+
# add convenience date attribute helpers / readers
|
86
|
+
# - what to return if date is nil? - return nil or empty string or 'n/a' or '?' - why? why not?
|
87
|
+
#
|
88
|
+
# date
|
89
|
+
# date_iso | date_iso8601
|
90
|
+
# date_822 | date_rfc2822 | date_rfc822
|
91
|
+
|
92
|
+
def date() updated; end
|
93
|
+
|
94
|
+
def date_iso() date ? date.iso8601 : ''; end
|
95
|
+
alias_method :date_iso8601, :date_iso
|
96
|
+
|
97
|
+
def date_822() date ? date.rfc822 : ''; end
|
98
|
+
alias_method :date_rfc2822, :date_822
|
99
|
+
alias_method :date_rfc822, :date_822
|
100
|
+
|
101
|
+
|
81
102
|
## "raw" access via data "proxy" helper
|
82
103
|
## e.g. use feed.data.updated
|
83
104
|
## feed.data.updated? etc.
|
84
105
|
class Data
|
85
106
|
def initialize( feed ) @feed = feed; end
|
86
|
-
|
107
|
+
|
87
108
|
def url() @feed.read_attribute( :url ); end # "regular" url incl. auto_url fallback / (auto-)backup
|
88
109
|
def title() @feed.read_attribute( :title ); end
|
89
110
|
def feed_url() @feed.read_attribute( :feed_url ); end
|
90
111
|
def url?() url.present?; end
|
91
112
|
def title?() title.present?; end
|
92
113
|
def feed_url?() feed_url.present?; end
|
93
|
-
|
114
|
+
|
94
115
|
def updated() @feed.read_attribute(:updated); end # "regular" updated incl. published fallback
|
95
|
-
def published() @feed.read_attribute(:published); end
|
116
|
+
def published() @feed.read_attribute(:published); end # "regular" published incl. updated fallback
|
96
117
|
def updated?() updated.present?; end
|
97
118
|
def published?() published.present?; end
|
98
119
|
end # class Data
|
99
120
|
## use a different name for data - why? why not?
|
100
121
|
## e.g. inner, internal, readonly or r, raw, table, direct, or ???
|
101
|
-
def data() @data ||= Data.new( self ); end
|
102
|
-
|
103
|
-
|
122
|
+
def data() @data ||= Data.new( self ); end
|
123
|
+
|
124
|
+
|
104
125
|
def deep_update_from_struct!( data )
|
105
126
|
|
106
127
|
logger = LogUtils::Logger.root
|
@@ -207,8 +228,8 @@ class Feed < ActiveRecord::Base
|
|
207
228
|
published: data.published,
|
208
229
|
summary: data.summary,
|
209
230
|
generator: data.generator.to_s, ## note: use single-line/string generator stringified -- might return null (if no data)
|
210
|
-
|
211
|
-
## note: always auto-update auto_* fields for now
|
231
|
+
|
232
|
+
## note: always auto-update auto_* fields for now
|
212
233
|
auto_title: data.title,
|
213
234
|
auto_url: data.url,
|
214
235
|
auto_feed_url: data.feed_url,
|
data/lib/pluto/models/item.rb
CHANGED
@@ -42,25 +42,47 @@ class Item < ActiveRecord::Base
|
|
42
42
|
|
43
43
|
## note:
|
44
44
|
## only use fallback for updated, that is, updated (or published)
|
45
|
-
## do NOT use fallback for published / created -- why? why not
|
46
|
-
def updated()
|
47
|
-
def
|
45
|
+
## ~~do NOT use fallback for published / created -- why? why not?~~
|
46
|
+
def updated() read_attribute_w_fallbacks( :updated, :published ); end
|
47
|
+
def published() read_attribute_w_fallbacks( :published, :updated ); end
|
48
|
+
|
49
|
+
def updated?() updated.present?; end
|
50
|
+
def published?() published.present?; end
|
51
|
+
|
52
|
+
#############
|
53
|
+
# add convenience date attribute helpers / readers
|
54
|
+
# - what to return if date is nil? - return nil or empty string or 'n/a' or '?' - why? why not?
|
55
|
+
#
|
56
|
+
# date
|
57
|
+
# date_iso | date_iso8601
|
58
|
+
# date_822 | date_rfc2822 | date_rfc822
|
59
|
+
|
60
|
+
def date() updated; end
|
61
|
+
|
62
|
+
def date_iso() date ? date.iso8601 : ''; end
|
63
|
+
alias_method :date_iso8601, :date_iso
|
64
|
+
|
65
|
+
def date_822() date ? date.rfc822 : ''; end
|
66
|
+
alias_method :date_rfc2822, :date_822
|
67
|
+
alias_method :date_rfc822, :date_822
|
68
|
+
|
48
69
|
|
49
70
|
## "raw" access via data "proxy" helper
|
50
71
|
## e.g. use item.data.updated
|
51
72
|
## item.data.updated? etc.
|
52
73
|
class Data
|
53
74
|
def initialize( feed ) @item = item; end
|
54
|
-
|
75
|
+
|
55
76
|
def updated() @item.read_attribute(:updated); end # "regular" updated incl. published fallback
|
56
|
-
def published() @item.read_attribute(:published); end
|
77
|
+
def published() @item.read_attribute(:published); end
|
78
|
+
|
57
79
|
def updated?() updated.present?; end
|
58
80
|
def published?() published.present?; end
|
59
81
|
end # class Data
|
60
82
|
## use a different name for data - why? why not?
|
61
83
|
## e.g. inner, internal, readonly or r, raw, table, direct, or ???
|
62
|
-
def data() @data ||= Data.new( self ); end
|
63
|
-
|
84
|
+
def data() @data ||= Data.new( self ); end
|
85
|
+
|
64
86
|
|
65
87
|
def update_from_struct!( data )
|
66
88
|
|
data/lib/pluto/version.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.6.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: 2020-02-
|
11
|
+
date: 2020-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.1.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: date-formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.1
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: textutils
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|