homesteading_post 0.0.3 → 0.0.4
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/app/models/homesteading/post.rb +50 -3
- data/lib/homesteading_post/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7d4023679d71c7072b4c97a67703e22d371211
|
4
|
+
data.tar.gz: 2c001d648fbde11b9dc232d127b5db5fcaa23d15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb17cd8590d9bd5e7ae2b621390652b83de3a33ccc3eefa72dfbc7b8fddf54ac3c866a997dd75345afdbbad475139059bca43d573e431efdec505c5ae6154b91
|
7
|
+
data.tar.gz: 83b710da9187a65cdf681e0970414076433e544810cfa232838fcca95c4fd17d5b310042800178720575e97ab5245fd85f3dc9bdcf269657663d7cfc5cddd59c
|
@@ -1,11 +1,58 @@
|
|
1
1
|
module Homesteading
|
2
2
|
class Post < ActiveRecord::Base
|
3
|
+
default_scope { order("published_at desc") }
|
4
|
+
|
5
|
+
validates :published_at, :year, :month, :day, :hour, :minute, :second, :slug,
|
6
|
+
presence:true, unless: :new_record?
|
7
|
+
|
8
|
+
before_create :set_published_at_attrs, :set_slug
|
9
|
+
before_update :set_published_at_attrs, :set_slug
|
3
10
|
|
4
11
|
self.abstract_class = true
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
"
|
13
|
+
|
14
|
+
def path
|
15
|
+
post_type = Setting.where(name: "Post Type").first.content.downcase.pluralize
|
16
|
+
"/" + [post_type, year.to_s.rjust(2, "0"), month.rjust(2, "0"), day.rjust(2, "0"), slug].compact.join("/")
|
17
|
+
end
|
18
|
+
|
19
|
+
def params
|
20
|
+
{ year: year, month: month, day: day, slug: slug }
|
21
|
+
end
|
22
|
+
|
23
|
+
def public?
|
24
|
+
!self.private?
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
content
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_published_at_attrs
|
34
|
+
self.published_at ||= Time.zone.now
|
35
|
+
self.year = published_at.year
|
36
|
+
self.month = published_at.month.to_s.rjust(2, "0")
|
37
|
+
self.day = published_at.day.to_s.rjust( 2, "0")
|
38
|
+
self.hour = published_at.hour.to_s.rjust( 2, "0")
|
39
|
+
self.minute = published_at.min.to_s.rjust( 2, "0")
|
40
|
+
self.second = published_at.sec.to_s.rjust( 2, "0")
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_slug
|
44
|
+
blank = ""
|
45
|
+
separator = "-"
|
46
|
+
self.slug ||= "#{name || content}"
|
47
|
+
self.slug = slug.downcase.
|
48
|
+
gsub(/\(|\)|\[|\]\./, blank).
|
49
|
+
gsub(/&/, blank).
|
50
|
+
gsub(/\W+/, separator).
|
51
|
+
gsub(/_+/, separator).
|
52
|
+
gsub(/ +/, separator).
|
53
|
+
gsub(/-+/, separator).
|
54
|
+
gsub(/^-+/, blank).
|
55
|
+
gsub(/-+$/, blank)
|
9
56
|
end
|
10
57
|
|
11
58
|
end
|