ruby_context 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +44 -8
  3. data/lib/context/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 311b29f865030830c138fbc9fc9ee85161520a4dfc8a1e3f59610d9730155dbf
4
- data.tar.gz: 3990ec078678b4a36753d3a5a71a3cebffe6291c98163358e13da70eae3e97a2
3
+ metadata.gz: aa4cfd9c78dde837339350593fe18953bcfcc0972cf48935f0f9f2cc50caf167
4
+ data.tar.gz: 47bfd71c36db62e7ed4f6707422e3823fc196bcef2bd2e40a2bce81d91905686
5
5
  SHA512:
6
- metadata.gz: e87afe19d22a0a3f75a3b233f6d4b415fa01b02e0e41804fe2e4d8513bb9a24595675ea862d56c6b8de905d0a24e0721d84cf0af14ef585c14aa56b6dd1ad1f1
7
- data.tar.gz: e9ec3676ff4aec12f5b4656707a2bd38c552462f25417b6d8c6a7d04df857245908f8e7fea0882b40cca9cffbf4ac42aaa74ec7456b2a0cd68ada2607551d12f
6
+ metadata.gz: 3f9754848dadb5e698c055170f7d10c8a8e5bacfbfa24896d6621607fb20244388de7340c643aecc9b71bb91abeb020bfbf1e61df59434c4ee7ab0569f60ab83
7
+ data.tar.gz: f11a80e627984406a0db3e82c7ba756245863a9929da7f2c394022bacbef6e2ee4a400a416da86778e6d50e723dc45152d5dec7a2de23347066aa70075ebc0e7
data/README.md CHANGED
@@ -1,28 +1,64 @@
1
- # Context
1
+ # Ruby Context
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/context`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ This gem allows you to define and override global values inspired in [Reactjs Context api](https://reactjs.org/docs/context.html)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ You can use this gem in any ruby project, including Rails.
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'context'
12
+ gem 'ruby-context'
13
13
  ```
14
14
 
15
15
  And then execute:
16
16
 
17
17
  $ bundle
18
18
 
19
- Or install it yourself as:
19
+ ## Usage in Rails
20
20
 
21
- $ gem install context
21
+ imagine you want to override rails logger
22
22
 
23
- ## Usage
23
+ Create a config/initializers/app_logger.rb
24
24
 
25
- TODO: Write usage instructions here
25
+ ```ruby
26
+ # Default value isn't necessary, but good
27
+
28
+ APP_LOGGER = Context::Context.new(default_value: Rails.logger)
29
+ ```
30
+
31
+ Image you have a worker called send_mail_worker.rb and you want that every call to Rails.logger should be override to a different log.
32
+
33
+ ```ruby
34
+ class SendMailWorker
35
+ def do_work
36
+ email_logger = Logger.new
37
+ APP_LOGGER.with(email_logger) do
38
+ MailService.run!
39
+ end
40
+ end
41
+ end
42
+ ```
43
+
44
+ So now every calls of APP_LOGGER will not call Rails.logger anymore, but email_logger!
45
+
46
+ ```ruby
47
+ class MailService
48
+ def self.run!
49
+ APP_LOGGER.info "runing mail service"
50
+ OtherClass.execute!
51
+ end
52
+ end
53
+ ```
54
+
55
+ ```ruby
56
+ class OtherClass
57
+ def self.execute!
58
+ APP_LOGGER.info "executing"
59
+ end
60
+ end
61
+ ```
26
62
 
27
63
  ## Development
28
64
 
@@ -1,3 +1,3 @@
1
1
  module Context
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manoel Quirino