This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new custom event and context structures
- Loading branch information
1 parent
025c59f
commit 791da67
Showing
10 changed files
with
104 additions
and
21 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 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
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
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,16 @@ | ||
module Timber | ||
module Util | ||
# @private | ||
module Struct | ||
extend self | ||
|
||
def to_hash(struct) | ||
h = {} | ||
struct.each_pair do |k ,v| | ||
h[k] = v | ||
end | ||
h | ||
end | ||
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,49 @@ | ||
require "spec_helper" | ||
|
||
describe Timber::Contexts, :rails_23 => true do | ||
describe ".build" do | ||
it "should build a Timber::Context" do | ||
context = Timber::Contexts::Custom.new( | ||
type: :build, | ||
data: {version: "1.0.0"} | ||
) | ||
built_context = Timber::Contexts.build(context) | ||
expect(built_context).to eq(context) | ||
end | ||
|
||
it "should use #to_timber_context" do | ||
BuildContext = Struct.new(:version) do | ||
def to_timber_context | ||
Timber::Contexts::Custom.new( | ||
type: :build, | ||
data: respond_to?(:to_h) ? to_h : Timber::Util::Struct.to_hash(self) | ||
) | ||
end | ||
end | ||
built_context = Timber::Contexts.build(BuildContext.new("1.0.0")) | ||
expect(built_context).to be_kind_of(Timber::Contexts::Custom) | ||
expect(built_context.type).to eq(:build) | ||
Object.send(:remove_const, :BuildContext) | ||
end | ||
|
||
it "should accept a properly structured hash" do | ||
built_context = Timber::Contexts.build(build: {version: "1.0.0"}) | ||
expect(built_context).to be_kind_of(Timber::Contexts::Custom) | ||
expect(built_context.type).to eq(:build) | ||
end | ||
|
||
it "should accept a struct" do | ||
BuildContext = Struct.new(:version) do | ||
def type; :build; end | ||
end | ||
built_context = Timber::Contexts.build(BuildContext.new("1.0.0")) | ||
expect(built_context).to be_kind_of(Timber::Contexts::Custom) | ||
expect(built_context.type).to eq(:build) | ||
Object.send(:remove_const, :BuildContext) | ||
end | ||
|
||
it "should return nil for unsupported" do | ||
expect(Timber::Contexts.build(1)).to be_nil | ||
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
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