Skip to content

Commit

Permalink
Merge 1626890 into c076e09
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Nov 25, 2018
2 parents c076e09 + 1626890 commit 5e7272d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
6 changes: 5 additions & 1 deletion bin/cron_job.rb
Expand Up @@ -6,5 +6,9 @@
job = Ayashige::Jobs::CronJob.new
job.perform
rescue StandardError => e
Rollbar.error e
if Ayashige::Rollbar.available?
Rollbar.error e
else
puts e
end
end
8 changes: 6 additions & 2 deletions lib/ayashige.rb
Expand Up @@ -11,14 +11,18 @@

require "ayashige/sources/web_analyzer"

require "ayashige/rollbar"

require "ayashige/application"

require "ayashige/jobs/cron_job"

require "rollbar"

Rollbar.configure do |config|
config.access_token = ENV["ROLLBAR_ACCESS_TOKEN"]
if Ayashige::Rollbar.available?
Rollbar.configure do |config|
config.access_token = ENV["ROLLBAR_ACCESS_TOKEN"]
end
end

module Ayashige
Expand Down
2 changes: 1 addition & 1 deletion lib/ayashige/application.rb
Expand Up @@ -5,7 +5,7 @@

module Ayashige
class Application < Sinatra::Base
use Rollbar::Middleware::Sinatra
use ::Rollbar::Middleware::Sinatra if Ayashige::Rollbar.available?

configure do
set :root, File.dirname(__FILE__) + '/../..'
Expand Down
11 changes: 11 additions & 0 deletions lib/ayashige/rollbar.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Ayashige
class Rollbar
ROLLBAR_KEY = "ROLLBAR_ACCESS_TOKEN"

def self.available?
ENV.key? ROLLBAR_KEY
end
end
end
21 changes: 21 additions & 0 deletions spec/rollbar_spec.rb
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe Ayashige::Rollbar do
subject { Ayashige::Rollbar }

describe "#available?" do
context "when ROLLBAR_ACCESS_TOKEN is set" do
before do
allow(ENV).to receive(:key?).with("ROLLBAR_ACCESS_TOKEN").and_return(true)
end
it "should return true" do
expect(subject.available?).to eq(true)
end
end
context "when ROLLBAR_ACCESS_TOKEN is not set" do
it "should return false" do
expect(subject.available?).to eq(false)
end
end
end
end

0 comments on commit 5e7272d

Please sign in to comment.