effective_resources 2.25.1 → 2.25.3
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/controllers/concerns/effective/crud_controller/actions.rb +0 -2
- data/app/controllers/concerns/effective/crud_controller.rb +5 -0
- data/app/models/concerns/acts_as_published.rb +66 -0
- data/lib/effective_resources/engine.rb +1 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 109b49a58f8065098757d3ddcc03b01598cf088c05c635134f359aab00eaa2a3
|
4
|
+
data.tar.gz: 80dc0801db689a5abeebc2d1e2c7d08b726f20dc8b3731993a435e119b138cfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2eb4ae03a4ee413ffe9ecae44679e1c12dc45167f1515a971cd20bdcfb773dac587cba1cbf31bfa38205b447b4fc8d00a9842b26aaf94cb58be4ce91cbf10a1
|
7
|
+
data.tar.gz: 99fdfe50066864c0618a460ab4c5e78fb97f66daf37ac7f46323781e2c7bc6a99f49e562002c71a0fd9749ea443b1f0effff1deb9142082c4f76ac5e87d6ad68
|
@@ -109,7 +109,6 @@ module Effective
|
|
109
109
|
format.html { }
|
110
110
|
format.js { render('show', formats: :js) }
|
111
111
|
end
|
112
|
-
|
113
112
|
end
|
114
113
|
|
115
114
|
def edit
|
@@ -126,7 +125,6 @@ module Effective
|
|
126
125
|
format.html { }
|
127
126
|
format.js { render('edit', formats: :js) }
|
128
127
|
end
|
129
|
-
|
130
128
|
end
|
131
129
|
|
132
130
|
def update
|
@@ -14,6 +14,11 @@ module Effective
|
|
14
14
|
included do
|
15
15
|
define_callbacks :resource_render, :resource_before_save, :resource_after_save, :resource_after_commit, :resource_error
|
16
16
|
layout -> { resource_layout }
|
17
|
+
|
18
|
+
# For effective_logging acts_as_trackable
|
19
|
+
after_action(only: [:show], if: -> { resource.present? && resource.class.try(:acts_as_trackable?) }) do
|
20
|
+
resource.track!(user: try(:current_user), details: request.params)
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
24
|
module ClassMethods
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# ActsAsPublished
|
3
|
+
#
|
4
|
+
# Adds published and draft scopes. Adds published? and draft? methods
|
5
|
+
#
|
6
|
+
# add_column :things, :published_start_at, :datetime
|
7
|
+
# add_column :things, :published_end_at, :datetime
|
8
|
+
#
|
9
|
+
module ActsAsPublished
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
module Base
|
13
|
+
def acts_as_published(options = nil)
|
14
|
+
include ::ActsAsPublished
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def acts_as_published?; true; end
|
20
|
+
end
|
21
|
+
|
22
|
+
included do
|
23
|
+
attr_writer :save_as_draft
|
24
|
+
|
25
|
+
before_validation do
|
26
|
+
assign_attributes(published_start_at: nil, published_end_at: nil) if EffectiveResources.truthy?(@save_as_draft)
|
27
|
+
end
|
28
|
+
|
29
|
+
validate(if: -> { published_start_at.present? && published_end_at.present? }) do
|
30
|
+
errors.add(:published_end_at, 'must be after the published start date') if published_end_at <= published_start_at
|
31
|
+
end
|
32
|
+
|
33
|
+
scope :draft, -> {
|
34
|
+
where(published_start_at: nil)
|
35
|
+
.or(where(arel_table[:published_start_at].gt(Time.zone.now)))
|
36
|
+
.or(where(arel_table[:published_end_at].lteq(Time.zone.now)))
|
37
|
+
}
|
38
|
+
|
39
|
+
scope :published, -> {
|
40
|
+
(try(:unarchived) || all)
|
41
|
+
.where(arel_table[:published_start_at].lteq(Time.zone.now))
|
42
|
+
.where(published_end_at: nil).or(where(arel_table[:published_end_at].gteq(Time.zone.now)))
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
# Instance Methods
|
47
|
+
def published?
|
48
|
+
return false if published_start_at.blank? || published_start_at > Time.zone.now
|
49
|
+
return false if published_end_at.present? && published_end_at <= Time.zone.now
|
50
|
+
return false if try(:archived?)
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
def draft?
|
56
|
+
return true if published_start_at.blank? || published_start_at > Time.zone.now
|
57
|
+
return true if published_end_at.present? && published_end_at <= Time.zone.now
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
# For the form
|
62
|
+
def save_as_draft
|
63
|
+
persisted? && published_start_at.blank? && published_end_at.blank?
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -29,6 +29,7 @@ module EffectiveResources
|
|
29
29
|
ActiveRecord::Base.extend(ActsAsSlugged::Base)
|
30
30
|
ActiveRecord::Base.extend(ActsAsStatused::Base)
|
31
31
|
ActiveRecord::Base.extend(ActsAsPaginable::Base)
|
32
|
+
ActiveRecord::Base.extend(ActsAsPublished::Base)
|
32
33
|
ActiveRecord::Base.extend(ActsAsWizard::Base)
|
33
34
|
ActiveRecord::Base.extend(ActsAsPurchasableWizard::Base)
|
34
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.25.
|
4
|
+
version: 2.25.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- app/models/concerns/acts_as_email_form.rb
|
204
204
|
- app/models/concerns/acts_as_email_notification.rb
|
205
205
|
- app/models/concerns/acts_as_paginable.rb
|
206
|
+
- app/models/concerns/acts_as_published.rb
|
206
207
|
- app/models/concerns/acts_as_purchasable_wizard.rb
|
207
208
|
- app/models/concerns/acts_as_slugged.rb
|
208
209
|
- app/models/concerns/acts_as_statused.rb
|