active_notify 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4798a47e79d588463c152b3d13519ff711f930665d6df5627476df0839b47498
4
+ data.tar.gz: 7abe28ebfd584b03aef4e3863c69ae56d1645fab75f09f77c24e54aa23643560
5
+ SHA512:
6
+ metadata.gz: d9e2ad2a47116a60d6d5fb00735f6a7001c33ca1cfede913315bc880cf2561e91907043e31febefaf3c3c2852321fbb5855f38959834ff5d5e3a95664745ead3
7
+ data.tar.gz: 17658892a2ae5d1c191a7bb2b3b4d2d69fa0b7b2462df51d0b68c7f819a1b7dddd5665a3beca1915eae5aa63903d23d3479cab942baa6d1d9cb7072cb0d3ff42
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-04-11
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 abeidahmed
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Active Notify
2
+
3
+ WIP
4
+
5
+ ## Installation
6
+
7
+ WIP
8
+
9
+ ## Usage
10
+
11
+ WIP
12
+
13
+ ## Development
14
+
15
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
+
17
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/abeidahmed/active_notify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/active_notify/blob/main/CODE_OF_CONDUCT.md).
22
+
23
+ ## License
24
+
25
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
26
+
27
+ ## Code of Conduct
28
+
29
+ Everyone interacting in the ActiveNotify project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_notify/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,62 @@
1
+ require "active_support/core_ext/class/attribute"
2
+ require_relative "delivery_config"
3
+ require_relative "callbacks"
4
+
5
+ module ActiveNotify
6
+ class Base
7
+ include Callbacks
8
+
9
+ class_attribute :deliveries, instance_writer: false, default: {}
10
+
11
+ class << self
12
+ def notify_via(delivery_name, options = {})
13
+ self.deliveries = deliveries.merge(delivery_name => DeliveryConfig.new(delivery_name, options))
14
+ define_delivery_callbacks(delivery_name)
15
+ end
16
+
17
+ def notify_now
18
+ new.notify_now
19
+ end
20
+
21
+ def notify_later(...)
22
+ new.notify_later(...)
23
+ end
24
+
25
+ def with(params)
26
+ new(params)
27
+ end
28
+ end
29
+
30
+ attr_reader :params
31
+
32
+ def initialize(params = {})
33
+ @params = params
34
+ end
35
+
36
+ def notify_now
37
+ perform_deliveries do |instance|
38
+ instance.notify_now
39
+ end
40
+ end
41
+
42
+ def notify_later(*args)
43
+ perform_deliveries do |instance|
44
+ instance.notify_later(*args)
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def perform_deliveries
51
+ run_notify_callbacks do
52
+ deliveries.each do |name, config|
53
+ next unless config.notify?(self)
54
+
55
+ run_delivery_callbacks(name) do
56
+ yield config.constant.new(self)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,45 @@
1
+ require "active_support/callbacks"
2
+ require "active_support/concern"
3
+
4
+ module ActiveNotify
5
+ module Callbacks
6
+ extend ActiveSupport::Concern
7
+ include ActiveSupport::Callbacks
8
+
9
+ included do
10
+ define_callbacks :notify
11
+ end
12
+
13
+ class_methods do
14
+ def define_delivery_callbacks(delivery_name)
15
+ define_callbacks delivery_name
16
+ end
17
+
18
+ %i[before after around].each do |kind|
19
+ define_method "#{kind}_notify" do |*names, on: :notify, **options, &block|
20
+ names.each do |name|
21
+ set_callback on, kind, name, options
22
+ end
23
+
24
+ set_callback on, kind, block, options if block
25
+ end
26
+
27
+ define_method "skip_#{kind}_notify" do |*names, on: :notify, **options|
28
+ names.each do |name|
29
+ skip_callback on, kind, name, options
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def run_notify_callbacks(&)
38
+ run_callbacks(:notify, &)
39
+ end
40
+
41
+ def run_delivery_callbacks(delivery_name, &)
42
+ run_callbacks(delivery_name, &)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ require "active_support/core_ext/module/delegation"
2
+
3
+ module ActiveNotify
4
+ class Delivery
5
+ delegate :params, to: :notifier
6
+
7
+ def initialize(notifier)
8
+ @notifier = notifier
9
+ end
10
+
11
+ def notify_now
12
+ # Override in subclasses to handle this notification.
13
+ end
14
+
15
+ def notify_later(*)
16
+ # Override in subclasses to handle this notification.
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :notifier
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ module ActiveNotify
2
+ class DeliveryConfig
3
+ attr_reader :name, :options
4
+
5
+ def initialize(delivery_name, options = {})
6
+ @delivery_name = delivery_name
7
+ @options = options
8
+ end
9
+
10
+ def constant
11
+ options.fetch(:class_name).constantize
12
+ end
13
+
14
+ def notify?(context)
15
+ return false if options.key?(:if) && !evaluate(:if, context)
16
+ return false if options.key?(:unless) && evaluate(:unless, context)
17
+ true
18
+ end
19
+
20
+ private
21
+
22
+ def evaluate(kind, context)
23
+ condition = options[kind]
24
+
25
+ if condition.respond_to?(:call, true)
26
+ context.instance_exec(&condition)
27
+ elsif condition.is_a?(Symbol)
28
+ context.send(condition)
29
+ else
30
+ condition
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveNotify
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "active_notify/version"
2
+ require_relative "active_notify/base"
3
+ require_relative "active_notify/delivery"
4
+
5
+ module ActiveNotify
6
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - abeidahmed
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '6.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '6.1'
26
+ description: Rails framework for delivering notifications across multiple channels.
27
+ email:
28
+ - abeidahmed92@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - CHANGELOG.md
34
+ - LICENSE.txt
35
+ - README.md
36
+ - lib/active_notify.rb
37
+ - lib/active_notify/base.rb
38
+ - lib/active_notify/callbacks.rb
39
+ - lib/active_notify/delivery.rb
40
+ - lib/active_notify/delivery_config.rb
41
+ - lib/active_notify/version.rb
42
+ homepage: https://github.com/abeidahmed/active_notify
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ homepage_uri: https://github.com/abeidahmed/active_notify
47
+ source_code_uri: https://github.com/abeidahmed/active_notify
48
+ changelog_uri: https://github.com/abeidahmed/active_notify/CHANGELOG.md
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.2.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.6.9
64
+ specification_version: 4
65
+ summary: Rails framework for delivering notifications across multiple channels.
66
+ test_files: []