Skip to content

Commit

Permalink
Adds configuration for defining custom inbox model
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadnawzad committed Jan 22, 2024
1 parent a580870 commit ebe740c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## [Unreleased]

## [0.1.0] - 2024-01-21
## [0.1.1] - 2024-01-21

- Initial release
9 changes: 2 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
inboxable (0.1.0)
inboxable (0.1.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -43,16 +43,12 @@ GEM
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
mini_portile2 (2.8.5)
minitest (5.21.2)
mutex_m (0.2.0)
nokogiri (1.16.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.3.0.4)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
prism (0.19.0)
Expand Down Expand Up @@ -139,7 +135,6 @@ GEM
yard (0.9.34)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand Down
4 changes: 4 additions & 0 deletions lib/inboxable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Error < StandardError; end
class << self
attr_accessor :configuration

def inbox_model
@configuration.inbox_model.constantize
end

def configure
@configuration ||= Configuration.new
yield(@configuration) if block_given?
Expand Down
6 changes: 5 additions & 1 deletion lib/inboxable/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Inboxable
class Configuration
ALLOWED_ORMS = %i[activerecord mongoid].freeze

attr_accessor :orm
attr_accessor :orm, :inbox_model

def initialize
raise Error, 'Sidekiq is not available. Unfortunately, sidekiq must be available for Inboxable to work' unless Object.const_defined?('Sidekiq')
Expand All @@ -23,5 +23,9 @@ def orm=(orm)
def orm
@orm || :activerecord
end

def inbox_model
@inbox_model || 'Inbox'
end
end
end
4 changes: 2 additions & 2 deletions lib/inboxable/polling_receiver_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform
end

def perform_activerecord
Inbox.pending
Inboxable.inbox_model.pending
.where(last_attempted_at: [..Time.zone.now, nil])
.find_in_batches(batch_size: ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i)
.each do |batch|
Expand All @@ -22,7 +22,7 @@ def perform_activerecord

def perform_mongoid
batch_size = ENV.fetch('INBOXABLE__BATCH_SIZE', 100).to_i
Inbox.pending
Inboxable.inbox_model.pending
.any_of({ last_attempted_at: ..Time.zone.now }, { last_attempted_at: nil })
.each_slice(batch_size) do |batch|
batch.each do |inbox|
Expand Down
2 changes: 1 addition & 1 deletion lib/inboxable/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Inboxable
VERSION = '0.1.0'
VERSION = '0.1.1'
end

0 comments on commit ebe740c

Please sign in to comment.