-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #438 from rollbar/plugins
Add plugins architecture
- Loading branch information
Showing
47 changed files
with
736 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,4 @@ | ||
require "rollbar/js/version" | ||
|
||
module Rollbar | ||
module Js | ||
extend self | ||
|
||
attr_reader :framework | ||
attr_reader :framework_loader | ||
|
||
def prepare | ||
@framework ||= detect_framework | ||
@framework_loader ||= load_framework_class.new | ||
|
||
@framework_loader.prepare | ||
end | ||
|
||
private | ||
|
||
def detect_framework | ||
case | ||
when defined?(::Rails::VERSION) | ||
:rails | ||
end | ||
end | ||
|
||
def load_framework_class | ||
require "rollbar/js/frameworks/#{framework}" | ||
|
||
Rollbar::Js::Frameworks.const_get(framework.to_s.capitalize) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module Rollbar | ||
# Represents a plugin in the gem. Every plugin can have multiple dependencies | ||
# and multiple execution blocks. | ||
# On Rollbar initialization, all plugins will be saved in memory and those that | ||
# satisfy the dependencies will be loaded | ||
class Plugin | ||
attr_reader :name | ||
attr_reader :dependencies | ||
attr_reader :callables | ||
attr_accessor :loaded | ||
|
||
private :loaded= | ||
|
||
def initialize(name) | ||
@name = name | ||
@dependencies = [] | ||
@callables = [] | ||
@loaded = false | ||
end | ||
|
||
def configuration | ||
Rollbar.configuration | ||
end | ||
|
||
def load! | ||
return unless load? | ||
|
||
begin | ||
callables.each(&:call) | ||
rescue => e | ||
log_loading_error(e) | ||
ensure | ||
self.loaded = true | ||
end | ||
end | ||
|
||
private | ||
|
||
def dependency(&block) | ||
dependencies << block | ||
end | ||
|
||
def execute(&block) | ||
callables << block | ||
end | ||
|
||
def execute!(&block) | ||
block.call if load? | ||
end | ||
|
||
def load? | ||
!loaded && dependencies.all?(&:call) | ||
rescue => e | ||
log_loading_error(e) | ||
|
||
false | ||
end | ||
|
||
def log_loading_error(e) | ||
Rollbar.log_error("Error trying to load plugin '#{name}': #{e.class}, #{e.message}") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'rollbar/plugin' | ||
|
||
module Rollbar | ||
# Stores the available plugin definitions and loads them | ||
class Plugins | ||
attr_reader :collection | ||
|
||
def initialize | ||
@collection = [] | ||
end | ||
|
||
def require_all | ||
Dir.glob(plugin_files).each do |file| | ||
require file.to_s | ||
end | ||
end | ||
|
||
def plugin_files | ||
File.expand_path('../plugins/*.rb', __FILE__) | ||
end | ||
|
||
def define(name, &block) | ||
return if loaded?(name) | ||
|
||
plugin = Rollbar::Plugin.new(name) | ||
collection << plugin | ||
|
||
plugin.instance_eval(&block) | ||
end | ||
|
||
def load! | ||
collection.each(&:load!) | ||
end | ||
|
||
private | ||
|
||
def loaded?(name) | ||
collection.any? { |plugin| plugin.name == name } | ||
end | ||
end | ||
end |
File renamed without changes.
Oops, something went wrong.