effective_resources 2.25.2 → 2.25.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2967108f64775ddd3de0531e80509fe3f4c4b369fdb3b2b59a96103b2082e516
|
4
|
+
data.tar.gz: 1a53e6935d666e80676aed79910447929aad82d45dad2430a82093d85af70056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e0d13115d6e1acdea84ee206a3bfc31fe3885b2f6384332a36f1bedeaf33f85f5066c8e364396998a627249df7d99ba3495c0d14117139ad9d6db0e09d76eb
|
7
|
+
data.tar.gz: e35ddd7ed8a8dcfce32a96a205a4aa9b8ca050b64d6accc3b7e4f134c9e7c04dd728a84426671f72afa3f2512d38f9f752b9e043a7c01efc7b19aa3c09a20e23
|
@@ -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.4
|
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-
|
11
|
+
date: 2024-07-02 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
|