restforce-db 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 407cce0ebad34c7bc0ae9f7be7ddc30a447946e0
4
- data.tar.gz: f3a011122809e8f20fc187c8fb3f304b1316d14d
3
+ metadata.gz: a2214ab04231e0cbbc83e59248f3f3ec794c01c4
4
+ data.tar.gz: 560a485242bce00d2b9d219c8775c6854736bb59
5
5
  SHA512:
6
- metadata.gz: 2468e281554a0b657f18bada83b0ba75f8ffa1cdd8368a7dd04333274443d79d474aab6562effea8cd8444e793c11408915c5d57e7b4c01144bc66a9320b5e9c
7
- data.tar.gz: 88e9bd543a9ce246eee0074abec601b997f582c66cd63d4052b3e6a6c2340f346679f059662c5ca1eecc95eb1d05a4cad3fc455f92299320b87ed58316ae1cf8
6
+ metadata.gz: cbde0d9e95daf9e7eace6492aa9fb3a552bc766c807b34db2ea24ef369b8471651784244b767024db2b8d3e1f904b4e2d3cb4325d85b8a6c325515a0233fbf87
7
+ data.tar.gz: 928e76319b07d113d6d551a4128307ed4d63bc77c3fcf104201fff6fe2aa25167fbd49f508640ae166b97ae4d1e464718ccff23948eafd63a92353626dc584db
data/README.md CHANGED
@@ -224,6 +224,18 @@ For additional information and a full set of options, you can run:
224
224
 
225
225
  $ bundle exec bin/restforce-db -h
226
226
 
227
+ #### Configuring the daemon's runtime environment
228
+
229
+ Restforce::DB allows you to configure up a block of code which will execute when the daemon process forks. In an initializer (or any other piece of code which will run as your application spins up), you can use `config.after_fork` to set up this hook:
230
+
231
+ ```ruby
232
+ Restforce::DB.configure do |config|
233
+ config.after_fork { ActiveRecord::Base.logger = nil }
234
+ end
235
+ ```
236
+
237
+ The example above would disable the default ActiveRecord logging specifically for activity triggered by the Restforce::DB daemon.
238
+
227
239
  ## System Caveats
228
240
 
229
241
  - **API Usage.**
@@ -56,9 +56,16 @@ module Restforce
56
56
  def run(options = {})
57
57
  Dir.chdir(Rails.root)
58
58
 
59
- Restforce::DB::Worker.after_fork
60
59
  Restforce::DB.logger = logger
61
60
 
61
+ # This hook comes from the FileDaemon module, and keeps file descriptors
62
+ # opened after the process forks.
63
+ Restforce::DB::Worker.after_fork
64
+
65
+ # This hook can be configured in an initializer, and allows changes to
66
+ # the runtime environment after the process forks.
67
+ Restforce::DB.after_fork
68
+
62
69
  worker = Restforce::DB::Worker.new(options)
63
70
  worker.logger = logger
64
71
  worker.tracker = tracker
@@ -18,8 +18,31 @@ module Restforce
18
18
  client_secret
19
19
  host
20
20
  api_version
21
+ logger
21
22
  ))
22
23
 
24
+ # Public: Allow an after_fork callback to be configured or run. Runs the
25
+ # previously-configured block if called without arguments.
26
+ #
27
+ # block - A block of code to execute after process forking.
28
+ #
29
+ # Returns nothing.
30
+ def after_fork(&block)
31
+ if block_given?
32
+ @after_fork ||= block
33
+ else
34
+ @after_fork.call if @after_fork
35
+ end
36
+ end
37
+
38
+ # Public: Get the configured logger. Returns a null logger if no logger
39
+ # has been configured yet.
40
+ #
41
+ # Returns a Logger.
42
+ def logger
43
+ @logger ||= Logger.new("/dev/null")
44
+ end
45
+
23
46
  # Public: Parse a supplied YAML file for a set of credentials, and use
24
47
  # them to populate the attributes on this configuraton object.
25
48
  #
@@ -3,7 +3,7 @@ module Restforce
3
3
  # :nodoc:
4
4
  module DB
5
5
 
6
- VERSION = "2.1.4"
6
+ VERSION = "2.1.5"
7
7
 
8
8
  end
9
9
 
data/lib/restforce/db.rb CHANGED
@@ -57,7 +57,15 @@ module Restforce
57
57
  class << self
58
58
 
59
59
  attr_accessor :last_run
60
- attr_writer :configuration, :logger
60
+ attr_writer :configuration
61
+
62
+ extend Forwardable
63
+ def_delegators(
64
+ :configuration,
65
+ :logger,
66
+ :logger=,
67
+ :after_fork,
68
+ )
61
69
 
62
70
  end
63
71
 
@@ -68,13 +76,6 @@ module Restforce
68
76
  @configuration ||= Configuration.new
69
77
  end
70
78
 
71
- # Public: Get the current logger for Restforce::DB.
72
- #
73
- # Returns a Logger instance.
74
- def self.logger
75
- @logger ||= Logger.new("/dev/null")
76
- end
77
-
78
79
  # Public: Get a Restforce client based on the currently configured settings.
79
80
  #
80
81
  # Returns a Restforce::Data::Client instance.
@@ -8,6 +8,39 @@ describe Restforce::DB::Configuration do
8
8
  let(:secrets_file) { File.expand_path("../../../../config/secrets.yml", __FILE__) }
9
9
  let(:configuration) { Restforce::DB::Configuration.new }
10
10
 
11
+ describe "#after_fork" do
12
+
13
+ it "does nothing if invoked without a block" do
14
+ # NOTE: We're asserting that this invocation doesn't raise an error.
15
+ configuration.after_fork
16
+ end
17
+
18
+ it "does not invoke the block on configuration" do
19
+ a = 1
20
+
21
+ configuration.after_fork { a += 1 }
22
+
23
+ expect(a).to_equal 1
24
+ end
25
+
26
+ it "invokes the configured block when called without arguments" do
27
+ a = 1
28
+
29
+ configuration.after_fork { a += 1 }
30
+ configuration.after_fork
31
+
32
+ expect(a).to_equal 2
33
+ end
34
+ end
35
+
36
+ describe "#logger" do
37
+
38
+ it "defaults to a null logger" do
39
+ log_device = configuration.logger.instance_variable_get("@logdev")
40
+ expect(log_device.dev.path).to_equal "/dev/null"
41
+ end
42
+ end
43
+
11
44
  describe "#load" do
12
45
 
13
46
  describe "when all configurations are supplied" do
@@ -4,20 +4,6 @@ describe Restforce::DB do
4
4
 
5
5
  configure!
6
6
 
7
- describe "#logger" do
8
-
9
- it "defaults to a null logger" do
10
- log_device = Restforce::DB.logger.instance_variable_get("@logdev")
11
- expect(log_device.dev.path).to_equal "/dev/null"
12
- end
13
-
14
- it "allows assignment of a new logger" do
15
- logger = Logger.new("/dev/null")
16
- Restforce::DB.logger = logger
17
- expect(Restforce::DB.logger).to_equal logger
18
- end
19
- end
20
-
21
7
  describe "#configure" do
22
8
 
23
9
  it "yields a Configuration" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Horner
@@ -193,7 +193,6 @@ files:
193
193
  - ".gitignore"
194
194
  - ".rubocop.yml"
195
195
  - ".rubocop/custom/method_documentation.rb"
196
- - ".travis.yml"
197
196
  - Gemfile
198
197
  - LICENSE.txt
199
198
  - README.md
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.0