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

Add context functionality #5

Merged
merged 3 commits into from
Apr 25, 2012
Merged

Add context functionality #5

merged 3 commits into from
Apr 25, 2012

Conversation

asenchi
Copy link
Owner

@asenchi asenchi commented Apr 24, 2012

This allows one to set a context earlier in an application or provide a
context for a block.

This allows one to set a context earlier in an application
or provide a context for a block.
@mmcgrana
Copy link

Is there an example available of how this would be used in an app and what the results would be? This would help illustrate the problem that this is trying to solve.

@asenchi
Copy link
Owner Author

asenchi commented Apr 24, 2012

Sure, so I see two uses that people have requested and this PR fulfills. One was yours and another Fabio's.

Scrolls.context(:request_id => "f49f0ba0-7073-012f-6f14-64ce8f596974") do
  request_method
end

This would prefix every Scrolls.log call within the block.

Scrolls.context(:app => :railgun, :deploy => "production")

This would prefix all Scrolls.log usage for the entire application.

@mmcgrana
Copy link

Right. Here is an executation example that further illustrates how this works:

1.9.2p318 :001 > require "./lib/scrolls"
 => true 
1.9.2p318 :002 > Scrolls::Log.start
 => true 
1.9.2p318 :003 > Scrolls.context(:global => "g")
 => nil 
1.9.2p318 :004 > Scrolls.log(:local => "l")
global=g local=l
 => nil 
1.9.2p318 :005 > Scrolls.context(:around => "a") { Scrolls.log(:local => "l") }
global=g around=a local=l
 => {:global=>"g"} 
1.9.2p318 :006 > Scrolls.context(:around => "a") { Scrolls.context(:inner => "i") { Scrolls.log(:local => "l") } }
global=g around=a inner=i local=l
 => {:global=>"g", :around=>"a"} 
1.9.2p318 :007 > Scrolls.log(:local => "l")
global=g around=a local=l

Actually that last bit might be a bug?

@asenchi
Copy link
Owner Author

asenchi commented Apr 24, 2012

Yep, that last one is a bug. I think I see what is happening.

asenchi added a commit that referenced this pull request Apr 25, 2012
Add context functionality
@asenchi asenchi merged commit ba712a7 into master Apr 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants