Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: Zeitwerk #84

Draft
wants to merge 1 commit into
base: 01-06-chore_removed_object_blank_monkey_patch
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 19 additions & 49 deletions lib/vero.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
# frozen_string_literal: true

require "base64"
require "json"
require "rest-client"

module Vero
autoload :Config, "vero/config"
autoload :App, "vero/app"
autoload :Context, "vero/context"
autoload :APIContext, "vero/context/api"
autoload :Trackable, "vero/trackable"
autoload :DSL, "vero/dsl"
autoload :Sender, "vero/sender"
autoload :SuckerPunchWorker, "vero/senders/sucker_punch"
autoload :ResqueWorker, "vero/senders/resque"
autoload :SidekiqWorker, "vero/senders/sidekiq"

module Api
module Workers
autoload :BaseAPI, "vero/api/base_api"

module Events
autoload :TrackAPI, "vero/api/events/track_api"
end

module Users
autoload :TrackAPI, "vero/api/users/track_api"
autoload :EditAPI, "vero/api/users/edit_api"
autoload :EditTagsAPI, "vero/api/users/edit_tags_api"
autoload :UnsubscribeAPI, "vero/api/users/unsubscribe_api"
autoload :ResubscribeAPI, "vero/api/users/resubscribe_api"
autoload :ReidentifyAPI, "vero/api/users/reidentify_api"
autoload :DeleteAPI, "vero/api/users/delete_api"
end
end

autoload :Events, "vero/api"
autoload :Users, "vero/api"
end

module Senders
autoload :Base, "vero/senders/base"
autoload :DelayedJob, "vero/senders/delayed_job"
autoload :Resque, "vero/senders/resque"
autoload :Sidekiq, "vero/senders/sidekiq"
autoload :Invalid, "vero/senders/invalid"
autoload :SuckerPunch, "vero/senders/sucker_punch"
end

module Utility
autoload :Logger, "vero/utility/logger"
end
end
require "zeitwerk"

loader = Zeitwerk::Loader.for_gem
loader.inflector.inflect(
"api_context" => "APIContext",
"dsl" => "DSL",
"base_api" => "BaseAPI",
"track_api" => "TrackAPI",
"delete_api" => "DeleteAPI",
"edit_api" => "EditAPI",
"edit_tags_api" => "EditTagsAPI",
"reidentify_api" => "ReidentifyAPI",
"resubscribe_api" => "ResubscribeAPI",
"unsubscribe_api" => "UnsubscribeAPI"
)
loader.ignore("#{__dir__}/generators")
loader.setup

require "vero/railtie" if defined?(Rails)
99 changes: 0 additions & 99 deletions lib/vero/api.rb

This file was deleted.

27 changes: 27 additions & 0 deletions lib/vero/api/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

class Vero::Api::Base
attr_accessor :context

def initialize(context)
self.context = context
end

def config
context.config
end

def run_api(api_klass, options)
return if config.disabled

validate_configured!
options.merge!(config.request_params)
Vero::Sender.send(api_klass, config.async, config.domain, options)
end

protected

def validate_configured!
raise "You must configure the 'vero' gem. Visit https://github.com/getvero/vero for more details." unless config.configured?
end
end
71 changes: 0 additions & 71 deletions lib/vero/api/base_api.rb

This file was deleted.

11 changes: 11 additions & 0 deletions lib/vero/api/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class Vero::Api::Events < Vero::Api::Base
def self.track!(options, context = Vero::App.default_context)
new(context).track!(options)
end

def track!(options)
run_api(Vero::Api::Workers::Events::TrackAPI, options)
end
end
24 changes: 0 additions & 24 deletions lib/vero/api/events/track_api.rb

This file was deleted.

57 changes: 57 additions & 0 deletions lib/vero/api/users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class Vero::Api::Users < Vero::Api::Base
def self.track!(options, context = Vero::App.default_context)
new(context).track!(options)
end

def self.edit_user!(options, context = Vero::App.default_context)
new(context).edit_user!(options)
end

def self.edit_user_tags!(options, context = Vero::App.default_context)
new(context).edit_user_tags!(options)
end

def self.reidentify!(options, context = Vero::App.default_context)
new(context).reidentify!(options)
end

def self.unsubscribe!(options, context = Vero::App.default_context)
new(context).unsubscribe!(options)
end

def self.resubscribe!(options, context = Vero::App.default_context)
new(context).resubscribe!(options)
end

def self.delete!(options, context = Vero::App.default_context)
new(context).delete!(options)
end

def track!(options)
run_api(Vero::Api::Workers::Users::TrackAPI, options)
end

def edit_user!(options)
run_api(Vero::Api::Workers::Users::EditAPI, options)
end

def edit_user_tags!(options)
run_api(Vero::Api::Workers::Users::EditTagsAPI, options)
end

def unsubscribe!(options)
run_api(Vero::Api::Workers::Users::UnsubscribeAPI, options)
end

def resubscribe!(options)
run_api(Vero::Api::Workers::Users::ResubscribeAPI, options)
end

def reidentify!(options)
run_api(Vero::Api::Workers::Users::ReidentifyAPI, options)
end

def delete!(options)
run_api(Vero::Api::Workers::Users::DeleteAPI, options)
end
end
23 changes: 0 additions & 23 deletions lib/vero/api/users/delete_api.rb

This file was deleted.

Loading
Loading