undercarriage 0.1.0 → 0.4.1

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.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -4
  3. data/lib/undercarriage.rb +15 -3
  4. data/lib/undercarriage/controllers/action_concern.rb +18 -0
  5. data/lib/undercarriage/controllers/kaminari_concern.rb +11 -0
  6. data/lib/undercarriage/controllers/locale_concern.rb +7 -1
  7. data/lib/undercarriage/controllers/restful/actions/base_concern.rb +120 -0
  8. data/lib/undercarriage/controllers/restful/actions/create_concern.rb +107 -0
  9. data/lib/undercarriage/controllers/restful/actions/destroy_concern.rb +97 -0
  10. data/lib/undercarriage/controllers/restful/actions/edit_concern.rb +94 -0
  11. data/lib/undercarriage/controllers/restful/actions/index_concern.rb +85 -0
  12. data/lib/undercarriage/controllers/restful/actions/new_concern.rb +96 -0
  13. data/lib/undercarriage/controllers/restful/actions/show_concern.rb +91 -0
  14. data/lib/undercarriage/controllers/restful/actions/update_concern.rb +105 -0
  15. data/lib/undercarriage/controllers/restful/flash_concern.rb +112 -0
  16. data/lib/undercarriage/controllers/restful/location_after_concern.rb +79 -0
  17. data/lib/undercarriage/controllers/restful/namespace_concern.rb +41 -0
  18. data/lib/undercarriage/controllers/restful/permitted_attributes_concern.rb +109 -0
  19. data/lib/undercarriage/controllers/restful/utility_concern.rb +74 -0
  20. data/lib/undercarriage/controllers/restful_concern.rb +34 -0
  21. data/lib/undercarriage/models/published_concern.rb +120 -0
  22. data/lib/undercarriage/version.rb +4 -1
  23. metadata +17 -4
  24. data/lib/tasks/undercarriage_tasks.rake +0 -6
  25. data/lib/undercarriage/railtie.rb +0 -6
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ ##
9
+ # Utility
10
+ #
11
+ # Utility helper methods
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::Restful::UtilityConcern
16
+ # end
17
+ #
18
+ module UtilityConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ protected
22
+
23
+ ##
24
+ # Singular controller name
25
+ #
26
+ def controller_name_singular
27
+ controller_name.to_s.singularize
28
+ end
29
+
30
+ ##
31
+ # Singular human name
32
+ #
33
+ def controller_name_singular_human
34
+ controller_name_singular.humanize
35
+ end
36
+
37
+ ##
38
+ # Model name
39
+ #
40
+ def model_name
41
+ controller_name_singular
42
+ end
43
+
44
+ ##
45
+ # Model class
46
+ #
47
+ def model_class
48
+ model_name.classify.constantize
49
+ end
50
+
51
+ ##
52
+ # Instances name
53
+ #
54
+ def instances_name
55
+ controller_name.to_s
56
+ end
57
+
58
+ ##
59
+ # Instance name
60
+ #
61
+ def instance_name
62
+ model_name
63
+ end
64
+
65
+ ##
66
+ # Resource scope
67
+ #
68
+ def resource_scope
69
+ model_name.to_sym
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ ##
7
+ # Restful actions
8
+ #
9
+ # Usage
10
+ # class ExamplesController < ApplicationController
11
+ # include Undercarriage::Controllers::RestfulConcern
12
+ # end
13
+ #
14
+ module RestfulConcern
15
+ extend ActiveSupport::Concern
16
+
17
+ included do
18
+ include Undercarriage::Controllers::Restful::FlashConcern
19
+ include Undercarriage::Controllers::Restful::LocationAfterConcern
20
+ include Undercarriage::Controllers::Restful::NamespaceConcern
21
+ include Undercarriage::Controllers::Restful::PermittedAttributesConcern
22
+ include Undercarriage::Controllers::Restful::UtilityConcern
23
+ include Undercarriage::Controllers::Restful::Actions::BaseConcern
24
+ include Undercarriage::Controllers::Restful::Actions::IndexConcern
25
+ include Undercarriage::Controllers::Restful::Actions::ShowConcern
26
+ include Undercarriage::Controllers::Restful::Actions::NewConcern
27
+ include Undercarriage::Controllers::Restful::Actions::CreateConcern
28
+ include Undercarriage::Controllers::Restful::Actions::EditConcern
29
+ include Undercarriage::Controllers::Restful::Actions::UpdateConcern
30
+ include Undercarriage::Controllers::Restful::Actions::DestroyConcern
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Models
6
+ ##
7
+ # Published
8
+ #
9
+ # Based on the presence of a datetime in the `published_at` column (configurable) in the database. If there is a
10
+ # datetime in the column, it is considered published. You need to do your own validation to ensure the value is a
11
+ # datetime value
12
+ #
13
+ # Usage
14
+ # # Model
15
+ # class Example < ApplicationRecord
16
+ # include Undercarriage::Models::PublishedConcern
17
+ #
18
+ # ##
19
+ # # The name of the column is expected to be `published_at`. If that is not the case for you, uncomment the
20
+ # # following to change the column name
21
+ # #
22
+ # # self.published_column = :ready_at
23
+ #
24
+ # ##
25
+ # # The following are useful helpers for the model. They are not part of the concern
26
+ # #
27
+ # scope :available, -> { published.where("#{published_column} <= ?", Time.current) }
28
+ #
29
+ # def available?
30
+ # published? && self[published_column] <= Time.current
31
+ # end
32
+ #
33
+ # scope :scheduled, -> { published.where("#{published_column} > ?", , Time.current) }
34
+ #
35
+ # def scheduled?
36
+ # published? && self[published_column] > Time.current
37
+ # end
38
+ # end
39
+ #
40
+ # # Controller
41
+ # class PagesController < AdminController
42
+ # def index
43
+ # @examples = Example.published
44
+ # end
45
+ # end
46
+ #
47
+ # # View
48
+ # <% @examples.each do |example| %>
49
+ # Published?: <%= example.published? %>
50
+ # <% end %>
51
+ #
52
+ module PublishedConcern
53
+ extend ActiveSupport::Concern
54
+
55
+ included do
56
+ class_attribute :published_column
57
+ self.published_column = :published_at
58
+
59
+ ##
60
+ # Published scope
61
+ #
62
+ # Retrieve only published resources
63
+ #
64
+ # Usage
65
+ # class PagesController < AdminController
66
+ # def index
67
+ # @examples = Example.published
68
+ # end
69
+ # end
70
+ #
71
+ scope :published, -> { where.not(published_column => nil) }
72
+
73
+ ##
74
+ # Unpublished scope
75
+ #
76
+ # Retrieve only unpublished resources
77
+ #
78
+ # Usage
79
+ # class PagesController < AdminController
80
+ # def index
81
+ # @examples = Example.unpublished
82
+ # end
83
+ # end
84
+ #
85
+ scope :unpublished, -> { where(published_column => nil) }
86
+ end
87
+
88
+ ##
89
+ # Published check
90
+ #
91
+ # Check if an item is published based on the presence of a value in the published column. This does not take into
92
+ # account whether the item is not currently available (scheduled). See module documentation for more information
93
+ #
94
+ # Usage
95
+ # @example.published? => true
96
+ # @example.published? => false
97
+ #
98
+ # @return [Boolean] if resource is published
99
+ #
100
+ def published?
101
+ self[self.class.published_column].present?
102
+ end
103
+
104
+ ##
105
+ # Unpublished check
106
+ #
107
+ # Check if an item is unpublished based on the lack of presence of a value in the published column
108
+ #
109
+ # Usage
110
+ # @example.unpublished? => true
111
+ # @example.unpublished? => false
112
+ #
113
+ # @return [Boolean] if resource is unpublished
114
+ #
115
+ def unpublished?
116
+ !published?
117
+ end
118
+ end
119
+ end
120
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Undercarriage
4
- VERSION = '0.1.0'
4
+ ##
5
+ # Undercarriage version
6
+ #
7
+ VERSION = '0.4.1'
5
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: undercarriage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Freerksen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-05 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -35,12 +35,25 @@ files:
35
35
  - MIT-LICENSE
36
36
  - README.md
37
37
  - Rakefile
38
- - lib/tasks/undercarriage_tasks.rake
39
38
  - lib/undercarriage.rb
40
39
  - lib/undercarriage/controllers/action_concern.rb
41
40
  - lib/undercarriage/controllers/kaminari_concern.rb
42
41
  - lib/undercarriage/controllers/locale_concern.rb
43
- - lib/undercarriage/railtie.rb
42
+ - lib/undercarriage/controllers/restful/actions/base_concern.rb
43
+ - lib/undercarriage/controllers/restful/actions/create_concern.rb
44
+ - lib/undercarriage/controllers/restful/actions/destroy_concern.rb
45
+ - lib/undercarriage/controllers/restful/actions/edit_concern.rb
46
+ - lib/undercarriage/controllers/restful/actions/index_concern.rb
47
+ - lib/undercarriage/controllers/restful/actions/new_concern.rb
48
+ - lib/undercarriage/controllers/restful/actions/show_concern.rb
49
+ - lib/undercarriage/controllers/restful/actions/update_concern.rb
50
+ - lib/undercarriage/controllers/restful/flash_concern.rb
51
+ - lib/undercarriage/controllers/restful/location_after_concern.rb
52
+ - lib/undercarriage/controllers/restful/namespace_concern.rb
53
+ - lib/undercarriage/controllers/restful/permitted_attributes_concern.rb
54
+ - lib/undercarriage/controllers/restful/utility_concern.rb
55
+ - lib/undercarriage/controllers/restful_concern.rb
56
+ - lib/undercarriage/models/published_concern.rb
44
57
  - lib/undercarriage/version.rb
45
58
  homepage: https://github.com/dfreerksen/undercarriage
46
59
  licenses:
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # desc "Explaining what the task does"
4
- # task :undercarriage do
5
- # # Task goes here
6
- # end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Undercarriage
4
- class Railtie < ::Rails::Railtie
5
- end
6
- end