stackdriver-core 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a6a8a73f6206ebeaf00e0a79f66f05793dd0c11
4
- data.tar.gz: 3f99877f0c26ddeba5666c5c947cab30bcb08b6a
3
+ metadata.gz: b45c580aedf6db0249b85c998c299b1b549e79fc
4
+ data.tar.gz: b0102ed722cc628e16836cdf64dde18493162399
5
5
  SHA512:
6
- metadata.gz: c01a8d3ab1f9d720de99c6831a041ac37bfb3dbb625d29777916275a754fe617fcf6b988e35d3d3c53eda8e0b3c2398890f674171d20f5692ce03e6f7acd835a
7
- data.tar.gz: 933cf1dc8bcaa82730989cc94f103b60881e971ffc74c2f0fd5152549bcebb468009fe0c03169b359c0a0a2d0c1a106467625cfdf958ca40accbf74c3ab42295
6
+ metadata.gz: 9a85f64d8201cfa290097d414d95c092be448b5eb6ad3ae55788f837be9da77bd7ef2a5fc5886453d0cc6f2cfcfea7a0b642c49063018ef2c3856ee87444244a
7
+ data.tar.gz: 5b616f814cf67f966d2ab60ec651a446e99df26acb85a8ee959e6dcfe32ecd15d3f47004da7342d482f9f94b7eaf5891c3f8fb690930fb9522f3783c78f471b4
@@ -0,0 +1,63 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "stackdriver/core/configuration"
17
+
18
+ module Google
19
+ module Cloud
20
+ ##
21
+ # @private Defines Google::Cloud.configure method. This will be the root
22
+ # configuration object shared by Stackdriver instrumentation libraries'
23
+ # configurations.
24
+ module Configuration
25
+ ##
26
+ # @private The shared Configuration object that all the Stackdriver
27
+ # instrumentation libraries will build on top of.
28
+ @@config = ::Stackdriver::Core::Configuration.new
29
+
30
+ ##
31
+ # Configure the default parameter for Google::Cloud. The values defined on
32
+ # this top level will be shared across all Stackdriver instrumentation
33
+ # libraries (Debugger, ErrorReporting, Logging, and Trace). These other
34
+ # libraries may also add sub configuration options under this.
35
+ #
36
+ # Possible configuration parameters:
37
+ # * project_id: The Google Cloud Project ID. Automatically discovered
38
+ # when running from GCP environments.
39
+ # * keyfile: The service account JSON file path. Automatically
40
+ # discovered when running from GCP environments.
41
+ # * use_debugger: Explicitly enable or disable Stackdriver Debugger
42
+ # instrumentation
43
+ # * use_error_reporting: Explicitly enable or disable Stackdriver Error
44
+ # Reporting instrumentation
45
+ # * use_logging: Explicitly enable or disable Stackdriver Logging
46
+ # instrumentation
47
+ # * use_trace: Explicitly enable or disable Stackdriver
48
+ #
49
+ # @return [Stackdriver::Core::Configuration] The configuration object
50
+ # the Google::Cloud module uses.
51
+ #
52
+ def configure
53
+ yield @@config if block_given?
54
+
55
+ @@config
56
+ end
57
+ end
58
+
59
+ # Immediately extend Google::Cloud::Configuration#configure
60
+ # into Google::Cloud.configure
61
+ extend Configuration
62
+ end
63
+ end
@@ -13,6 +13,8 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
+ require "google/cloud/configuration"
17
+ require "stackdriver/core/configuration"
16
18
  require "stackdriver/core/trace_context"
17
19
  require "stackdriver/core/version"
18
20
 
@@ -0,0 +1,127 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0oud
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Stackdriver
17
+ module Core
18
+ ##
19
+ # @private Helps organize configuration options for Stackdriver
20
+ # instrumentation libraries. It's initialized with a nested list of
21
+ # predefined category keys, then only allows getting and setting these
22
+ # predefined options.
23
+ #
24
+ # @example
25
+ # nested_categories = [:cat1, {cat2: [:cat3]}]
26
+ # config = Stackdriver::Core::Configuration.new nested_categories
27
+ #
28
+ # config.opt1 #=> nil
29
+ # config.opt1 = true #=> true
30
+ # config.opt1 #=> true
31
+ #
32
+ # config.cat1 #=> <Stackdriver::Core::Configuration>
33
+ # config.cat2.cat3 #=> <Stackdriver::Core::Configuration>
34
+ #
35
+ class Configuration
36
+ ##
37
+ # Constructs a new instance of Configuration object.
38
+ #
39
+ # @param [Symbol, Array<Symbol, Hash>, Hash<Symbol, (Array, Hash)>]
40
+ # categories A Symbol, or nested Array and Hash of sub configuration
41
+ # categories. A single symbol, or symbols in array, will be key(s) to
42
+ # next level of categories. Nested hash represent sub categories with
43
+ # further nested sub categories.
44
+ #
45
+ def initialize categories = {}
46
+ @configs = {}
47
+
48
+ add_options categories
49
+ end
50
+
51
+ ##
52
+ # Add nested sub configuration categories to a Configuration object
53
+ #
54
+ # @param [Symbol, Array<Symbol, Hash>, Hash<Symbol, (Array, Hash)>]
55
+ # categories A Symbol, or nested Array and Hash of sub configuration
56
+ # categories. A single symbol, or symbols in array, will be key(s) to
57
+ # next level of categories. Nested hash represent sub categories with
58
+ # further nested sub categories.
59
+ #
60
+ # @example
61
+ # config = Stackdriver::Core::Configuration.new
62
+ # config.cat1 #=> nil
63
+ # config.add_options {cat1: [:cat2]}
64
+ # config.cat1 #=> <Stackdriver::Core::Configuration>
65
+ # config.cat1.cat2 #=> <Stackdriver::Core::Configuration>
66
+ #
67
+ def add_options categories
68
+ categories = [categories].flatten(1)
69
+ categories.each do |sub_key|
70
+ case sub_key
71
+ when Symbol
72
+ self[sub_key] = self.class.new
73
+ when Hash
74
+ sub_key.each do |k, v|
75
+ self[k] = self.class.new v
76
+ end
77
+ else
78
+ fail ArgumentError \
79
+ "Configuration option can only be Symbol or Hash"
80
+ end
81
+ end
82
+ end
83
+
84
+ ##
85
+ # Assign an option with `key` to value, while forcing `key` to be a
86
+ # Symbol.
87
+ def []= key, value
88
+ @configs[key.to_sym] = value
89
+ end
90
+
91
+ ##
92
+ # Get the option with `key`, while forcing `key` to be a Symbol.
93
+ def [] key
94
+ @configs[key.to_sym]
95
+ end
96
+
97
+ ##
98
+ # Delete the option with `key`, while forcing `key` to be a Symbol.
99
+ def delete key
100
+ @configs.delete key.to_sym
101
+ end
102
+
103
+ ##
104
+ # Check if the Configuration object has this option
105
+ #
106
+ # @param [Symbol] key The key to check for.
107
+ #
108
+ # @return [Boolean] True if the inquired key is a valid option for this
109
+ # Configuration object. False otherwise.
110
+ #
111
+ def option? key
112
+ @configs.key? key.to_sym
113
+ end
114
+
115
+ ##
116
+ # @private Dynamic getters and setters
117
+ def method_missing mid, *args
118
+ method_string = mid.to_s
119
+ if method_string.chomp!("=")
120
+ self[method_string] = args.first
121
+ else
122
+ self[mid]
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -15,6 +15,6 @@
15
15
 
16
16
  module Stackdriver
17
17
  module Core
18
- VERSION = "1.0.0".freeze
18
+ VERSION = "1.1.0".freeze
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackdriver-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-01 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -147,11 +147,13 @@ files:
147
147
  - ".yardopts"
148
148
  - LICENSE
149
149
  - README.md
150
+ - lib/google/cloud/configuration.rb
150
151
  - lib/stackdriver-core.rb
151
152
  - lib/stackdriver/core.rb
153
+ - lib/stackdriver/core/configuration.rb
152
154
  - lib/stackdriver/core/trace_context.rb
153
155
  - lib/stackdriver/core/version.rb
154
- homepage: http://googlecloudplatform.github.io/google-cloud-ruby/
156
+ homepage: https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/stackdriver-core
155
157
  licenses:
156
158
  - Apache-2.0
157
159
  metadata: {}
@@ -171,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
173
  version: '0'
172
174
  requirements: []
173
175
  rubyforge_project:
174
- rubygems_version: 2.6.11
176
+ rubygems_version: 2.6.12
175
177
  signing_key:
176
178
  specification_version: 4
177
179
  summary: Internal shared library for Ruby Stackdriver integration