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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fccd3ba65ccfd908ef199e41930f736cd2f9022ca3113ee90186a96230a7cf8c
4
- data.tar.gz: a92a0518846b2d4996ba806f55e1a4f00df34ad6dcdd0501a3e4cd7292915bf5
3
+ metadata.gz: 559e80f965a59b18fcbf8a6e73794ec46271d0e42bee153bcc215d393343216e
4
+ data.tar.gz: b4d88ead8c3576c47cb52be8ac23c9e44f65add36e499e8072649f215302442d
5
5
  SHA512:
6
- metadata.gz: 45773941e2a9fd2775e2e75c736083072e2193f90b49e92711638e2776d9d2058f18649050ce97ad663e2eb0d7b82d929d0db23de859fd7ff96912c886f228fd
7
- data.tar.gz: 3d5cf0b390504b5cf2d342d8e92ecce6738798466579af5562f145d0c11866a924950d955e506e699c4af4d8c25c30ca8d4d186391482ce39dd23f469b3bd5a6
6
+ metadata.gz: 51e19014eb0a462810268058435a775dd25d02b69ba815ccbdce46e0a5a364b9e3553c246bb8a056f082cdb486410d8eb281a5abaddeca7fe2b9ab5afb8ed89b
7
+ data.tar.gz: 66caf3c904f4263eca9b6146c3e577a0712148179c478bfb1e1405de6ea496a0bcb4c6d44f8c04f2dc2480634e6e850d6b1714709d332c3bc61425ba8e4d0428
data/README.md CHANGED
@@ -14,7 +14,7 @@ Undercarriage is a set of concerns to add to your application to trim some of th
14
14
  Add to your application's Gemfile
15
15
 
16
16
  ```ruby
17
- gem 'undercarriage', '~> 0.2'
17
+ gem 'undercarriage', '~> 0.3'
18
18
  ```
19
19
 
20
20
  Run the bundle command
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Undercarriage
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  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.2.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