right_support 2.0.0 → 2.0.3

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.
data/README.rdoc CHANGED
@@ -157,3 +157,28 @@ methods:
157
157
  * String#to_const_path
158
158
 
159
159
  Net::StringEncoder applies and removes URL-escape, base64 and other encodings.
160
+
161
+ === Configuration
162
+
163
+ RightSupport::Config contains functionality, which provides possibility
164
+ to use human-readable yaml configuration files. For example, you have following yaml
165
+ file '/tmp/features_config.yml', with content:
166
+
167
+ eat:
168
+ khlav kalash: YES!
169
+ speak:
170
+ klingonese: false
171
+ belarusian: true
172
+
173
+ Then, if you would add configuration in you class, like:
174
+
175
+ class SweetestClass
176
+ CONFIG = RightSupport::Config.features('/tmp/features_config.yml')
177
+ end
178
+
179
+ * RightSupport::Config.features receives file` path, io or string.
180
+
181
+ Now you can call CONFIG['feature_group']['feature'], like:
182
+
183
+ * SweetestClass::CONFIG['eat']['khlav kalash'] would return 'YES!'
184
+ * SweetestClass::CONFIG['speak']['belarusian'] would return true
@@ -0,0 +1,95 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport::Config
24
+
25
+ # Returns new instance of FeatureSet class,
26
+ # with loaded from config_source configuration
27
+ #
28
+ # === Parameters
29
+ # config_source(IO|String):: File` path, IO or raw yaml.
30
+ #
31
+ # === Return
32
+ # (FeatureSet):: new instance of FeatureSet class
33
+ def self.features(config_source)
34
+ return FeatureSet.new(config_source)
35
+ end
36
+
37
+ class FeatureSet
38
+
39
+ attr_accessor :configuration_source
40
+ attr_accessor :configuration
41
+
42
+ # Create features configuration object
43
+ #
44
+ # === Parameters
45
+ # cfg_source(IO|String):: File path, IO or raw yaml.
46
+ def initialize(cfg_source)
47
+ @configuration = load(cfg_source)
48
+ end
49
+
50
+ # Returns configuration value
51
+ #
52
+ # === Parameters
53
+ # feature_group(String):: Feature group name
54
+ # feature(String|nil):: Feature name
55
+ #
56
+ # === Return
57
+ # (String|Boolean):: Configuration value
58
+ def [](feature_group, feature=nil)
59
+ return_value = true
60
+ if @configuration[feature_group]
61
+ if feature == nil
62
+ return_value = @configuration[feature_group]
63
+ else
64
+ return_value = @configuration[feature_group][feature]
65
+ end
66
+ else
67
+ return_value = RecursiveTrueClass.new
68
+ end
69
+ return_value = true if return_value == nil
70
+ return_value
71
+ end
72
+
73
+ # Load configuration source
74
+ #
75
+ # === Parameters
76
+ # something(IO|String|Hash):: File path, IO, raw YAML string, or a pre-loaded Hash
77
+ #
78
+ # === Return
79
+ # (Hash|nil):: Loaded yaml file
80
+ #
81
+ # === Raise
82
+ # (ArgumentError):: If configuration source can`t be loaded
83
+ def load(something)
84
+ return_value = nil
85
+ @configuration_source = something
86
+ raise ArgumentError, "Can't coerce #{something} into YAML/Hash" unless (return_value = YAMLConfig.read(something))
87
+ return_value
88
+ end
89
+
90
+ end
91
+
92
+ # Temporary alias for FeatureSet class, to avoid disrupting downstream development
93
+ Feature = FeatureSet
94
+
95
+ end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport::Config
24
+
25
+ # Recursive(according to []) implementation of TrueClass.
26
+ # To use, just do: true1 = RecTrueClass.new
27
+ # now you can do true1['a'], true1['a']['b'], ...
28
+ # and it will return
29
+ class RecursiveTrueClass
30
+
31
+ def initialize
32
+ @value = true
33
+ end
34
+
35
+ def [](something)
36
+ self
37
+ end
38
+
39
+ # supporting standart boolean
40
+ # opeimplementation
41
+ def ==(other)
42
+ @value==other
43
+ end
44
+
45
+ def &(other)
46
+ @value & other
47
+ end
48
+
49
+ def ^(other)
50
+ @value ^ other
51
+ end
52
+
53
+ def to_s
54
+ @value.to_s
55
+ end
56
+
57
+ def |(other)
58
+ @value | other
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ require 'yaml'
23
+
24
+ module RightSupport::Config
25
+
26
+ # Helper that encapsulates logic for loading YAML configuration hashes from various sources
27
+ # which can include strings, IO objects, or already-loaded YAML in the form of a Hash.
28
+ module YAMLConfig
29
+
30
+ class << self
31
+
32
+ # Load yaml source
33
+ #
34
+ # === Parameters
35
+ # something(IO|String|Hash):: File path, IO, raw YAML string, or a pre-loaded Hash
36
+ #
37
+ # === Returns
38
+ # (Boolean|Hash):: Loaded yaml file or false if a RuntimeError occurred while loading
39
+ def read(something)
40
+ return_value = false
41
+
42
+ begin
43
+ if something.kind_of?(Hash)
44
+ return_value = something
45
+ elsif File.exists?(something)
46
+ return_value = YAML.load_file(something)
47
+ else
48
+ return_value = YAML.load(something)
49
+ end
50
+ raise unless return_value.kind_of?(Hash)
51
+ rescue
52
+ return_value = false
53
+ end
54
+
55
+ return_value
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
@@ -0,0 +1,34 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport
24
+ #
25
+ # A namespace for configuration tools.
26
+ #
27
+ module Config
28
+
29
+ end
30
+ end
31
+
32
+ require 'right_support/config/feature_set'
33
+ require 'right_support/config/yaml_config'
34
+ require 'right_support/config/recursive_true_class'
@@ -53,6 +53,8 @@ module RightSupport::Data
53
53
  #must not be available!
54
54
  end
55
55
  end
56
+
57
+ avail
56
58
  end
57
59
 
58
60
  # Determine the default UUID implementation in this Ruby VM.
@@ -55,8 +55,8 @@ module RightSupport::Rack
55
55
 
56
56
  log_request_begin(logger, env)
57
57
  status, header, body = @app.call(env)
58
- log_request_end(logger, env, status, began_at)
59
58
  log_exception(logger, env['sinatra.error']) if env['sinatra.error']
59
+ log_request_end(logger, status, header, began_at)
60
60
 
61
61
  return [status, header, body]
62
62
  rescue Exception => e
@@ -87,16 +87,26 @@ module RightSupport::Rack
87
87
  query_info = ''
88
88
  end
89
89
 
90
+ # Session
91
+ if env['global_session']
92
+ cookie = env['global_session']
93
+ info = [ env['global_session'].id,
94
+ cookie.keys.map{|k| %{"#{k}"=>"#{cookie[k]}"} }.join(', ') ]
95
+ sess = %Q{Session ID: %s Session Data: {%s}} % info
96
+ else
97
+ sess = ""
98
+ end
99
+
90
100
  params = [
91
- remote_addr,
92
101
  env["REQUEST_METHOD"],
93
102
  env["PATH_INFO"],
94
103
  query_info,
95
- env["HTTP_VERSION"],
104
+ remote_addr,
105
+ sess,
96
106
  env["rack.request_uuid"] || ''
97
107
  ]
98
108
 
99
- logger.info %Q{Begin: %s "%s %s%s %s" %s} % params
109
+ logger.info %Q{Processing %s "%s%s" (for %s) %s Request ID: %s} % params
100
110
  end
101
111
 
102
112
  # Log end of request
@@ -109,16 +119,22 @@ module RightSupport::Rack
109
119
  #
110
120
  # === Return
111
121
  # always returns true
112
- def log_request_end(logger, env, status, began_at)
113
- duration = Time.now - began_at
122
+ def log_request_end(logger, status, headers, began_at)
123
+ duration = (Time.now - began_at) * 1000
124
+
125
+ content_length = if headers['Content-Length']
126
+ headers['Content-Length'].to_s
127
+ else
128
+ '-'
129
+ end
114
130
 
115
131
  params = [
116
- status,
117
132
  duration,
118
- env["rack.request_uuid"] || ''
133
+ status,
134
+ content_length,
119
135
  ]
120
136
 
121
- logger.info %Q{End: %d %0.3f %s} % params
137
+ logger.info %Q{Completed in %dms | %d | %s bytes} % params
122
138
  end
123
139
 
124
140
  # Log exception
data/lib/right_support.rb CHANGED
@@ -4,6 +4,7 @@ require 'thread'
4
4
  require 'right_support/ruby'
5
5
  require 'right_support/data'
6
6
  require 'right_support/crypto'
7
+ require 'right_support/config'
7
8
  require 'right_support/db'
8
9
  require 'right_support/log'
9
10
  require 'right_support/net'
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '2.0.0'
11
- s.date = '2012-03-23'
10
+ s.version = '2.0.3'
11
+ s.date = '2012-04-27'
12
12
 
13
13
  s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Sergey Enin']
14
14
  s.email = 'support@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 3
10
+ version: 2.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2012-03-23 00:00:00 -07:00
22
+ date: 2012-04-27 00:00:00 -07:00
23
23
  default_executable:
24
24
  dependencies: []
25
25
 
@@ -35,6 +35,10 @@ files:
35
35
  - LICENSE
36
36
  - README.rdoc
37
37
  - lib/right_support.rb
38
+ - lib/right_support/config.rb
39
+ - lib/right_support/config/feature_set.rb
40
+ - lib/right_support/config/recursive_true_class.rb
41
+ - lib/right_support/config/yaml_config.rb
38
42
  - lib/right_support/crypto.rb
39
43
  - lib/right_support/crypto/signed_hash.rb
40
44
  - lib/right_support/data.rb