undercarriage 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/undercarriage.rb +1 -0
- data/lib/undercarriage/models/published_concern.rb +119 -0
- data/lib/undercarriage/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 559e80f965a59b18fcbf8a6e73794ec46271d0e42bee153bcc215d393343216e
|
4
|
+
data.tar.gz: b4d88ead8c3576c47cb52be8ac23c9e44f65add36e499e8072649f215302442d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51e19014eb0a462810268058435a775dd25d02b69ba815ccbdce46e0a5a364b9e3553c246bb8a056f082cdb486410d8eb281a5abaddeca7fe2b9ab5afb8ed89b
|
7
|
+
data.tar.gz: 66caf3c904f4263eca9b6146c3e577a0712148179c478bfb1e1405de6ea496a0bcb4c6d44f8c04f2dc2480634e6e850d6b1714709d332c3bc61425ba8e4d0428
|
data/README.md
CHANGED
data/lib/undercarriage.rb
CHANGED
@@ -16,6 +16,7 @@ require 'undercarriage/controllers/restful/location_after_concern'
|
|
16
16
|
require 'undercarriage/controllers/restful/namespace_concern'
|
17
17
|
require 'undercarriage/controllers/restful/permitted_attributes_concern'
|
18
18
|
require 'undercarriage/controllers/restful/utility_concern'
|
19
|
+
require 'undercarriage/models/published_concern'
|
19
20
|
|
20
21
|
require 'undercarriage/railtie'
|
21
22
|
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Undercarriage
|
4
|
+
module Models
|
5
|
+
##
|
6
|
+
# Published
|
7
|
+
#
|
8
|
+
# Based on the presence of a datetime in the `published_at` column (configurable) in the database. If there is a
|
9
|
+
# datetime in the column, it is considered published. You need to do your own validation to ensure the value is a
|
10
|
+
# datetime value
|
11
|
+
#
|
12
|
+
# Usage
|
13
|
+
# # Model
|
14
|
+
# class Example < ApplicationRecord
|
15
|
+
# include Undercarriage::Models::PublishedConcern
|
16
|
+
#
|
17
|
+
# ##
|
18
|
+
# # The name of the column is expected to be `published_at`. If that is not the case for you, uncomment the
|
19
|
+
# # following to change the column name
|
20
|
+
# #
|
21
|
+
# # self.published_column = :ready_at
|
22
|
+
#
|
23
|
+
# ##
|
24
|
+
# # The following are useful helpers for the model. They are not part of the concern
|
25
|
+
# #
|
26
|
+
# scope :available, -> { published.where("#{published_column} <= ?", Time.current) }
|
27
|
+
#
|
28
|
+
# def available?
|
29
|
+
# published? && self[published_column] <= Time.current
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# scope :scheduled, -> { published.where("#{published_column} > ?", , Time.current) }
|
33
|
+
#
|
34
|
+
# def scheduled?
|
35
|
+
# published? && self[published_column] > Time.current
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# # Controller
|
40
|
+
# class PagesController < AdminController
|
41
|
+
# def index
|
42
|
+
# @examples = Example.published
|
43
|
+
# end
|
44
|
+
# end
|
45
|
+
#
|
46
|
+
# # View
|
47
|
+
# <% @examples.each do |example| %>
|
48
|
+
# Published?: <%= example.published? %>
|
49
|
+
# <% end %>
|
50
|
+
#
|
51
|
+
module PublishedConcern
|
52
|
+
extend ActiveSupport::Concern
|
53
|
+
|
54
|
+
included do
|
55
|
+
class_attribute :published_column
|
56
|
+
self.published_column = :published_at
|
57
|
+
|
58
|
+
##
|
59
|
+
# Published scope
|
60
|
+
#
|
61
|
+
# Retrieve only published resources
|
62
|
+
#
|
63
|
+
# Usage
|
64
|
+
# class PagesController < AdminController
|
65
|
+
# def index
|
66
|
+
# @examples = Example.published
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
scope :published, -> { where.not(published_column => nil) }
|
71
|
+
|
72
|
+
##
|
73
|
+
# Unpublished scope
|
74
|
+
#
|
75
|
+
# Retrieve only unpublished resources
|
76
|
+
#
|
77
|
+
# Usage
|
78
|
+
# class PagesController < AdminController
|
79
|
+
# def index
|
80
|
+
# @examples = Example.unpublished
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
#
|
84
|
+
scope :unpublished, -> { where(published_column => nil) }
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Published check
|
89
|
+
#
|
90
|
+
# Check if an item is published based on the presence of a value in the published column. This does not take into
|
91
|
+
# account whether the item is not currently available (scheduled). See module documentation for more information
|
92
|
+
#
|
93
|
+
# Usage
|
94
|
+
# @example.published? => true
|
95
|
+
# @example.published? => false
|
96
|
+
#
|
97
|
+
# @return [Boolean] if resource is published
|
98
|
+
#
|
99
|
+
def published?
|
100
|
+
self[self.class.published_column].present?
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Unpublished check
|
105
|
+
#
|
106
|
+
# Check if an item is unpublished based on the lack of presence of a value in the published column
|
107
|
+
#
|
108
|
+
# Usage
|
109
|
+
# @example.unpublished? => true
|
110
|
+
# @example.unpublished? => false
|
111
|
+
#
|
112
|
+
# @return [Boolean] if resource is unpublished
|
113
|
+
#
|
114
|
+
def unpublished?
|
115
|
+
!published?
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: undercarriage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Freerksen
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/undercarriage/controllers/restful/permitted_attributes_concern.rb
|
54
54
|
- lib/undercarriage/controllers/restful/utility_concern.rb
|
55
55
|
- lib/undercarriage/controllers/restful_concern.rb
|
56
|
+
- lib/undercarriage/models/published_concern.rb
|
56
57
|
- lib/undercarriage/railtie.rb
|
57
58
|
- lib/undercarriage/version.rb
|
58
59
|
homepage: https://github.com/dfreerksen/undercarriage
|