Skip to content

Commit

Permalink
feat: drop active_support dependency (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmad-elassuty authored Feb 3, 2021
1 parent ad4fe10 commit bd0796e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
14 changes: 0 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,16 @@ PATH
remote: .
specs:
event_router (0.3.0)
activesupport

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.1)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.8)
connection_pool (2.2.3)
diff-lcs (1.3)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.3)
oj (3.10.14)
parallel (1.19.2)
parser (2.7.1.4)
Expand Down Expand Up @@ -67,10 +56,7 @@ GEM
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (1.7.0)
zeitwerk (2.4.2)

PLATFORMS
ruby
Expand Down
3 changes: 0 additions & 3 deletions event_router.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

# Dependencies
spec.add_dependency 'activesupport'

# Development dependencies
spec.add_development_dependency 'oj'
spec.add_development_dependency 'pry'
Expand Down
8 changes: 5 additions & 3 deletions lib/event_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
require 'event_router/version'
require 'event_router/error'

require 'event_router/configuration'
require 'event_router/event'
require 'event_router/delivery_adapters/base'

require 'event_router/serializers/base'
require 'event_router/publisher'
require 'event_router/serializer'
require 'event_router/configuration'

require 'event_router/delivery_adapters/base'
require 'event_router/publisher'

module EventRouter
module_function
Expand Down
1 change: 0 additions & 1 deletion lib/event_router/delivery_adapters/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'sidekiq'

require 'event_router/serializer'
require 'event_router/helpers/event'

require_relative 'helpers/sidekiq'
Expand Down
33 changes: 24 additions & 9 deletions lib/event_router/event.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require 'securerandom'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/string/inflections'

require_relative 'destination'

Expand All @@ -11,9 +9,6 @@ class Event
attr_reader :uid, :created_at, :payload
attr_accessor :correlation_id

class_attribute :destinations, default: {}, instance_writer: false
class_attribute :options, instance_writer: false

def initialize(uid: SecureRandom.uuid, correlation_id: SecureRandom.uuid, created_at: Time.now, **payload)
@uid = uid
@correlation_id = correlation_id
Expand All @@ -33,21 +28,41 @@ def to_hash
alias to_h to_hash

def name
self.class.name.demodulize.underscore
self.class.name.gsub(/([a-z])([A-Z])/, '\1_\2').gsub(/.*::/, '').downcase
end

def destinations
self.class.destinations
end

def options
self.class.options
end

def options?
!options.nil?
end

class << self
def inherited(base)
base.destinations = destinations.dup
attr_reader :options

def inherited(subclass)
subclass.instance_variable_set(:@options, @options.dup)
subclass.instance_variable_set(:@destinations, @destinations.dup)

super
end

def deliver_to(name, opts = {})
destinations[name] = EventRouter::Destination.new(name, **opts)
end

def destinations
@destinations ||= {}
end

def event_options(opts)
self.options = opts
@options = opts
end

def publish(**attrs)
Expand Down

0 comments on commit bd0796e

Please sign in to comment.