effective_resources 2.25.2 → 2.25.3

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: 54c0b2966934b0403a5c4a15976201652884c57d6e5a32d5b33e063a19de9bc2
4
- data.tar.gz: d939422e59047f0f710ccb58119e6bba750a4bdc8e9c2252a6f2474b624d5032
3
+ metadata.gz: 109b49a58f8065098757d3ddcc03b01598cf088c05c635134f359aab00eaa2a3
4
+ data.tar.gz: 80dc0801db689a5abeebc2d1e2c7d08b726f20dc8b3731993a435e119b138cfa
5
5
  SHA512:
6
- metadata.gz: 80a671039f17f7d3f10908051fa1476b63b809c258e41ac3ccce2554ae047f3dc7a55432c18218203385b695981326e708500b990f5e6b6f3392bf314cdf162b
7
- data.tar.gz: 918a532aa474e74c277390644f4179dccfdf607fee10157f057a2e56b5be9b15623bed8901be944c8fb862b6a69c9e71426b52970ef7f919c377fd0f81614eec
6
+ metadata.gz: e2eb4ae03a4ee413ffe9ecae44679e1c12dc45167f1515a971cd20bdcfb773dac587cba1cbf31bfa38205b447b4fc8d00a9842b26aaf94cb58be4ce91cbf10a1
7
+ data.tar.gz: 99fdfe50066864c0618a460ab4c5e78fb97f66daf37ac7f46323781e2c7bc6a99f49e562002c71a0fd9749ea443b1f0effff1deb9142082c4f76ac5e87d6ad68
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.25.2'.freeze
2
+ VERSION = '2.25.3'.freeze
3
3
  end
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.2
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-27 00:00:00.000000000 Z
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