Skip to content

Commit

Permalink
Merge pull request #75 from Sija/develop
Browse files Browse the repository at this point in the history
v1.8.1
  • Loading branch information
Sija authored Dec 17, 2020
2 parents 6673db9 + 8fb2ee1 commit cfe72fc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 61 deletions.
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: raven
version: 1.8.0
version: 1.8.1

authors:
- Sijawusz Pur Rahnama <sija@sija.pl>
Expand All @@ -21,6 +21,6 @@ targets:
crash_handler:
main: src/crash_handler.cr

crystal: ~> 0.35
crystal: ">= 0.35.0"

license: MIT
5 changes: 0 additions & 5 deletions spec/raven/interface_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ describe Raven::Interface do
interface.some_attr.should eq("test")
end

it "can initialize with a block" do
interface = Raven::Interface::Test.new { |iface| iface.some_attr = "test" }
interface.some_attr.should eq("test")
end

it "serializes to a Hash" do
interface = Raven::Interface::Test.new(some_attr: "test")
interface.to_hash.should eq({:some_attr => "test"})
Expand Down
3 changes: 1 addition & 2 deletions src/raven/breadcrumb.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Raven
end

# A timestamp representing when the breadcrumb occurred.
property timestamp : Time
property timestamp : Time = Time.utc

# The type of breadcrumb. The default type is `:default` which indicates
# no specific handling. Other types are currently:
Expand Down Expand Up @@ -61,7 +61,6 @@ module Raven
any_json_property :data

def initialize(**options)
@timestamp = Time.utc
initialize_with **options
end

Expand Down
21 changes: 4 additions & 17 deletions src/raven/event.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ module Raven
property id : String

# Indicates when the logging record was created (in the Sentry SDK).
property timestamp : Time
property timestamp : Time = Time.utc

# The record severity. Defaults to `:error`.
property level : Severity?
property level : Severity? = :error

# :ditto:
def level=(severity : Symbol)
Expand Down Expand Up @@ -135,15 +135,15 @@ module Raven
exceptions.reverse!

values = exceptions.map do |e|
Interface::SingleException.new do |iface|
Interface::SingleException.new.tap do |iface|
iface.type = e.class.to_s
iface.value = e.to_s
iface.module = e.class.to_s.split("::")[0...-1].join("::")

iface.stacktrace =
if e.backtrace? && !backtraces.includes?(e.backtrace.object_id)
backtraces << e.backtrace.object_id
Interface::Stacktrace.new(backtrace: e.backtrace) do |stacktrace|
Interface::Stacktrace.new(backtrace: e.backtrace).tap do |stacktrace|
event.culprit = stacktrace.culprit
end
end
Expand All @@ -158,8 +158,6 @@ module Raven
@breadcrumbs = options[:breadcrumbs]? || Raven.breadcrumbs
@context = options[:context]? || Raven.context
@id = UUID.random.hexstring
@timestamp = Time.utc
@level = Severity::ERROR
@server_name = @configuration.server_name
@release = @configuration.release
@environment = @configuration.current_environment
Expand Down Expand Up @@ -187,17 +185,6 @@ module Raven
interface(name, **options)
end

def interface(name : Symbol, **options, &block)
interface = Interface[name]
@interfaces[interface.sentry_alias] = interface.new(**options) do |iface|
yield iface
end
end

def interface(name : Symbol, options : NamedTuple, &block)
interface(name, **options) { |iface| yield iface }
end

def message
interface(:message).try &.as(Interface::Message).unformatted_message
end
Expand Down
4 changes: 2 additions & 2 deletions src/raven/instance.cr
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ module Raven
def capture(klass : String, message : String, backtrace = nil, **options, &block)
formatted_message = "#{klass}: #{message}"
capture(formatted_message, **options) do |event|
ex = Interface::SingleException.new do |iface|
ex = Interface::SingleException.new.tap do |iface|
iface.module = klass.split("::")[0...-1].join("::")
iface.type = klass
iface.value = message

if backtrace
iface.stacktrace = Interface::Stacktrace.new(backtrace: backtrace) do |stacktrace|
iface.stacktrace = Interface::Stacktrace.new(backtrace: backtrace).tap do |stacktrace|
event.culprit = stacktrace.culprit
end
end
Expand Down
5 changes: 0 additions & 5 deletions src/raven/interface.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ module Raven
def initialize(**attributes)
initialize_with(**attributes)
end

def initialize(**attributes, &block)
initialize_with(**attributes)
yield self
end
end

def to_hash
Expand Down
29 changes: 21 additions & 8 deletions src/raven/log_backend.cr
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,27 @@ module Raven
# See `Event#logger`, `Breadcrumb#category`
property default_logger : String

def initialize(
*,
@record_breadcrumbs = false,
@capture_exceptions = false,
@capture_all = false,
@default_logger = "logger"
)
end
{% if compare_versions(Crystal::VERSION, "1.0.0-dev") >= 0 %}
def initialize(
dispatch_mode : ::Log::DispatchMode = :sync,
*,
@record_breadcrumbs = false,
@capture_exceptions = false,
@capture_all = false,
@default_logger = "logger"
)
super(dispatch_mode)
end
{% else %}
def initialize(
*,
@record_breadcrumbs = false,
@capture_exceptions = false,
@capture_all = false,
@default_logger = "logger"
)
end
{% end %}

protected delegate :ignored_logger?,
to: Raven.configuration
Expand Down
35 changes: 15 additions & 20 deletions src/raven/mixins/initialize_with.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,42 @@ module Raven
#
# NOTE: Magic inside!
module InitializeWith
def initialize_with(**attributes)
def initialize_with(attributes)
{% begin %}
%set = [] of Symbol

{%
properties = @type.methods
.select { |m| m.name.ends_with?('=') && m.args.size == 1 }
.map(&.name[0...-1].id)
.map(&.name[0...-1].symbolize)
.uniq
%}

{% for property in properties %}
if arg = attributes[{{ property.symbolize }}]?
unless %set.includes?({{ property.symbolize }})
self.{{ property }} = arg
%set << {{ property.symbolize }}
end
{% for name in properties %}
if arg = attributes[{{ name }}]?
self.{{ name.id }} = arg
end
{% end %}

{%
ivars = @type.instance_vars
.map { |v| {v.name.id, v.type.name} }
.map(&.name.symbolize)
.uniq
%}

{% for ivar in ivars %}
{% name = ivar[0]; type = ivar[1] %}
if arg = attributes[{{ name.symbolize }}]?
unless %set.includes?({{ name.symbolize }})
if arg.is_a?({{ type }})
@{{ name }} = arg
%set << {{ name.symbolize }}
end
{% for name in ivars %}
{% unless properties.includes?(name) %}
if arg = attributes[{{ name }}]?
@{{ name.id }} = arg
end
end
{% end %}
{% end %}
{% end %}

self
end

def initialize_with(**attributes)
initialize_with(attributes)
end
end
end
end

0 comments on commit cfe72fc

Please sign in to comment.