inboxable 0.1.0 → 0.1.2

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: 1207d628727126924ff331738cd526e2dc676964fae984d2b53c6cf97a664418
4
- data.tar.gz: 7163397c6d3bd6c90e3beca17957943dd38866d677b4c4057ddf1a14bcff9f33
3
+ metadata.gz: b4d81533a77f953ec0b2e7b5b7b86dee4da59cfec008aedad5a9234a8303d7dd
4
+ data.tar.gz: ac85e6bb520fed77412e3c233dd6ac9385f828244f744d79da820a964c3f2e55
5
5
  SHA512:
6
- metadata.gz: a0e65af5f85b964269d7e20525754ec0ebe8152ea9e3d946480af9ad29c973756a70bbd97a4034d11eb38bc97b777e618b58daae4afc19825c99c00ec21c3e3a
7
- data.tar.gz: b9da958286397e8b9fc7f165af001a5a234d4e582cf971b6fc6f21f29574078928cb12c6d6b52c99e5187c3867a540af0aca4be82e942c675c910217e8545b9f
6
+ metadata.gz: 84cbdd6b4070185a8ce0322225c76b4490b0ec78e415c924c47ba0bc0c0a632170e9ba946a17cebb992b372422cd2a3ef05890b8a6baeb8f67e365779539c007
7
+ data.tar.gz: ad3d25d9823c1a45288c49b402b2f92de3ff519415a02bbe3a40ced00b8c2f2316e795e6282911869c8136158552be696caa26d52543c5fbb288edb93184269d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
- ## [Unreleased]
1
+ # Changelog
2
+ This file is used to list changes made in each version of the inboxable gem.
2
3
 
3
- ## [0.1.0] - 2024-01-21
4
+ ## Inboxable 0.1.2 (2024-01-22)
4
5
 
5
- - Initial release
6
+ * Added scope for each status key in the `Inbox` model to fetch the
7
+ corresponding records.
8
+
9
+ ## Inboxable 0.1.1 (2024-01-22)
10
+
11
+ * Added `inbox_model` configuration to the `Configuration` class to allow for custom
12
+ inbox models.
13
+
14
+ ## Inboxable 0.1.0 (2024-01-22)
15
+
16
+ * Initial release
data/README.md CHANGED
@@ -80,7 +80,9 @@ The options are as follows:
80
80
 
81
81
  ## Inbox Model
82
82
 
83
- The Inbox model is used to store the messages in the inbox. The Inbox model is generated by the gem when you run the `rails g inboxable:install --orm <orm>` command. Based on the ORM that you are using, the gem will generate the appropriate model. The following is the structure of the Inbox model for ActiveRecord and Mongoid.
83
+ The Inbox model is used to store the messages in the inbox. The Inbox model is generated by the gem when you run the `rails g inboxable:install --orm <orm>` command. Based on the ORM that you are using, the gem will generate the appropriate model.The following is the structure of the Inbox model for ActiveRecord and Mongoid.
84
+
85
+ If you would like to use a different name for the Inbox model. You can configure it by setting the `inbox_model` config to the name of you custom defined model. See the [Configuration](#configuration) section below for more information.
84
86
 
85
87
  ### Fields & Attributes
86
88
 
@@ -123,7 +125,8 @@ The Inboxable gem provides a number of configuration options that can be used to
123
125
  ---
124
126
  | Option | Description | Default Value | Applied To |
125
127
  | --- | --- |------------------|---|
126
- | `orm` | The ORM that is used in the application. | `:active_record` | `/config/initializers/inboxable.rb` |
128
+ | `orm` | The ORM that is used in the application. | `:active_record` | `/config/initializers/z_inboxable.rb` |
129
+ | `inbox_model` | The name of the Inbox model. | `Inbox` | `/config/initializers/z_inboxable.rb` |
127
130
  |`INBOXABLE__CRON_POLL_INTERVAL` | The interval in seconds between each poll of the inbox. | `5` | Can be overridden by providing an environment variable with the same name. |
128
131
  |`INBOXABLE__CRON` | The cron expression that is used to poll the inbox. | `*/5 * * * * *` | Can be overridden by providing an environment variable with the same name. |
129
132
  |`INBOXABLE__BATCH_SIZE` | The number of messages to be processed in each batch. | `100` | Can be overridden by providing an environment variable with the same name. |
@@ -2,7 +2,7 @@ module Inboxable
2
2
  class Configuration
3
3
  ALLOWED_ORMS = %i[activerecord mongoid].freeze
4
4
 
5
- attr_accessor :orm
5
+ attr_accessor :orm, :inbox_model
6
6
 
7
7
  def initialize
8
8
  raise Error, 'Sidekiq is not available. Unfortunately, sidekiq must be available for Inboxable to work' unless Object.const_defined?('Sidekiq')
@@ -23,5 +23,9 @@ module Inboxable
23
23
  def orm
24
24
  @orm || :activerecord
25
25
  end
26
+
27
+ def inbox_model
28
+ @inbox_model || 'Inbox'
29
+ end
26
30
  end
27
31
  end
@@ -9,10 +9,10 @@ module Inboxable
9
9
  end
10
10
 
11
11
  def perform_activerecord
12
- Inbox.pending
13
- .where(last_attempted_at: [..Time.zone.now, nil])
14
- .find_in_batches(batch_size: ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i)
15
- .each do |batch|
12
+ Inboxable.inbox_model.pending
13
+ .where(last_attempted_at: [..Time.zone.now, nil])
14
+ .find_in_batches(batch_size: ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i)
15
+ .each do |batch|
16
16
  batch.each do |inbox|
17
17
  inbox.processor_class_name.constantize.perform_async(inbox.id)
18
18
  inbox.update(last_attempted_at: 1.minute.from_now, status: :processed, allow_processing: false)
@@ -22,9 +22,9 @@ module Inboxable
22
22
 
23
23
  def perform_mongoid
24
24
  batch_size = ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i
25
- Inbox.pending
26
- .any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: nil })
27
- .each_slice(batch_size) do |batch|
25
+ Inboxable.inbox_model.pending
26
+ .any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: nil })
27
+ .each_slice(batch_size) do |batch|
28
28
  batch.each do |inbox|
29
29
  inbox.processor_class_name.constantize.perform_async(inbox.id.to_s)
30
30
  inbox.update(last_attempted_at: 1.minute.from_now, status: :processed, allow_processing: false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Inboxable
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/inboxable.rb CHANGED
@@ -10,6 +10,10 @@ module Inboxable
10
10
  class << self
11
11
  attr_accessor :configuration
12
12
 
13
+ def inbox_model
14
+ @configuration.inbox_model.constantize
15
+ end
16
+
13
17
  def configure
14
18
  @configuration ||= Configuration.new
15
19
  yield(@configuration) if block_given?
@@ -19,6 +19,10 @@ class Inbox
19
19
 
20
20
  as_enum :status, %i[pending processed failed], field: { type: String, default: 'pending' }, map: :string
21
21
 
22
+ statuses.each_key do |key|
23
+ scope key, -> { where(status_cd: key) }
24
+ end
25
+
22
26
  validates :processor_class_name, presence: true
23
27
 
24
28
  after_create :process, if: proc { |resource| resource.allow_processing == true }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inboxable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muhammad Nawzad