homesteading_post 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd25f8f80439c52e82ce84691adceec88c7bf1e9
4
- data.tar.gz: 5f2fdd8da3a6de1ad2f75f7f485437c7b1e02283
3
+ metadata.gz: 1e7d4023679d71c7072b4c97a67703e22d371211
4
+ data.tar.gz: 2c001d648fbde11b9dc232d127b5db5fcaa23d15
5
5
  SHA512:
6
- metadata.gz: f97d7de51160c4e8d67783120cfc4553176095d3d39e3f819341c3cad211a7954cec8c4781daa5c26e18b5b45780dafe900f44ca5090ab021f578e978757f4e6
7
- data.tar.gz: ef10a8089da5cba08de9a073cfe4c87f83b274e5c6f1da933ec5f9470add121f47b0a247631befd504b3cc7c8febe7c66332d489be173507de955159372f55e4
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
- def test
7
- puts "works"
8
- "works"
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(/&amp;/, 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
@@ -1,3 +1,3 @@
1
1
  module HomesteadingPost
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homesteading_post
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Becker