right_support 2.8.32 → 2.8.33

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: a2006046eff88bf5bcadd1cbae03279872cada84
4
- data.tar.gz: 318dac67ca4962d08e4f990b92c6687b7bfa77c0
3
+ metadata.gz: fb9b8dbbf196cce60a01939073f03dd056ae8c22
4
+ data.tar.gz: f1d9aaf339977d0124b0f0f658a47cd6e28e678c
5
5
  SHA512:
6
- metadata.gz: 7a1c5c26f1e59fba43adb37a272f5d1876a5a7c05704b83aa75c45cf9c5437780974d70f74546923ea32c76d661adb8044ac76a8321f180ffbbb26edf56bf21a
7
- data.tar.gz: 0b03e8fa439261c5b64e62d673750d4d002fd022e179b846f51c6fcc9c2b732a2beefc7cc5de08737466a409f5dbf13d5594078fd4265aa10e38c8e4b68006e8
6
+ metadata.gz: 357ee9fddedc435739e1aa355a23f01d1177557b9a10bcd2149e60d0e20e360ee0aeafb39d5b497fecbed7b920e952aa94a4d85041df5b5e338e2fe662fd1881
7
+ data.tar.gz: 1a593d7bc80ef34e4fcabf650ed5c957f529bf9b9047fa27d46440f902d532163c72dbb39826b447e7f932a4faae58ef24bbb05c612776b2eb7ca626a2a9611b
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+
data/.simplecov ADDED
@@ -0,0 +1,6 @@
1
+ require 'coveralls'
2
+
3
+ Coveralls.wear_merged! do
4
+ add_filter "/features/"
5
+ add_filter "/spec/"
6
+ end
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 1.8
5
+ - 1.9
6
+ - 2.0
7
+ - 2.1
8
+ script:
9
+ - bundle exec rake ci:spec
10
+ - bundle exec rake ci:cucumber
11
+ - bundle exec rake coveralls:push
12
+ bundler_args: --without debugger development
data/Gemfile CHANGED
@@ -3,25 +3,31 @@ source 'https://rubygems.org'
3
3
  # Gems that RightSupport can optionally make use of, but which it does
4
4
  # not require to be installed. These would be 'optional dependencies'
5
5
  # if gemspecs allowed for them.
6
+ #
7
+ # Note that these are all require-nil because we want to simulate the behavior
8
+ # of the library in a context where it lazy-loads its optional dependencies.
6
9
  group :optional do
7
- gem 'net-ssh', '~> 2.0'
8
- gem 'mime-types', '~> 1.0' # mime-types 2.x is no longer compatible with Ruby 1.8 and mime-types 1.x is only being maintained for security issues
9
- gem 'rest-client', '~> 1.6'
10
- gem 'addressable', '~> 2.2.7'
10
+ gem 'net-ssh', '~> 2.0', :require => nil
11
+ # mime-types 2.x is no longer compatible with Ruby 1.8 and
12
+ # mime-types 1.x is only being maintained for security issues .. use 1.x for now, since we
13
+ # maintain 1.8 compatibility
14
+ gem 'mime-types', '~> 1.0', :require => nil
15
+ gem 'rest-client', '~> 1.6.7', :require => nil
16
+ gem 'addressable', '~> 2.2.7', :require => nil
11
17
  gem 'uuidtools', '~> 2.0', :require => nil
12
18
  gem 'simple_uuid', '~> 0.2', :require => nil
13
19
  gem 'uuid', '~> 2.3', :require => nil
14
- gem 'yajl-ruby', '~> 1.1'
20
+ gem 'json', '~> 1.8', :require => nil
15
21
  gem 'iconv', :platforms => :ruby_18
16
22
  end
17
23
 
18
- # Gems used during test and development of RightSupport, but which should be omitted as development
19
- # dependencies when generating the gemspec.
24
+ gem 'rake', '~> 10.0', :group=>[:development, :test]
25
+
26
+ # Gems used to run RightSupport tests; omitted from the gemspec, but available in CI.
20
27
  group :test do
21
- gem 'jeweler', '~> 2.0'
22
28
  gem 'flexmock', '~> 1.0'
23
29
  gem 'rspec', '~> 2.13.0'
24
- gem 'right_develop', '~> 2.1'
30
+ gem 'right_develop', '~> 3.1'
25
31
 
26
32
  # Cuke >= 1.3.3 depends on RubyGems > 2.0 without specifying that in its gemspec
27
33
  gem 'cucumber', ['~> 1.0', '< 1.3.3']
@@ -31,11 +37,15 @@ group :test do
31
37
  # Work around the bug by locking ourselves to 1.5.x, guaranteeing that we can install our bundle
32
38
  # under Ruby 1.8.
33
39
  gem 'nokogiri', '~> 1.5.0'
40
+
41
+ # Code coverage reporting and metrics pp
42
+ gem 'coveralls', :require => false
34
43
  end
35
44
 
36
- # Gems that are used for development and not for CI.
45
+ # Gems that are used purely for development; present in the gemspec, not available in CI.
37
46
  group :development do
47
+ gem 'jeweler', '~> 2.0'
38
48
  gem 'ruby-debug', :platforms => [:ruby_18]
39
49
  gem 'pry', :platforms => [:ruby_19, :ruby_20, :ruby_21]
40
- gem 'pry-byebug', :platforms => [:ruby_19, :ruby_20, :ruby_21]
41
- end
50
+ gem 'pry-byebug', :platforms => [:ruby_20, :ruby_21]
51
+ end
data/Gemfile.lock CHANGED
@@ -8,6 +8,12 @@ GEM
8
8
  debugger-linecache (~> 1.2)
9
9
  coderay (1.1.0)
10
10
  columnize (0.8.9)
11
+ coveralls (0.7.1)
12
+ multi_json (~> 1.3)
13
+ rest-client
14
+ simplecov (>= 0.7)
15
+ term-ansicolor
16
+ thor
11
17
  cucumber (1.3.2)
12
18
  builder (>= 2.1.2)
13
19
  diff-lcs (>= 1.1.3)
@@ -15,7 +21,7 @@ GEM
15
21
  multi_json (~> 1.3)
16
22
  debugger-linecache (1.2.0)
17
23
  diff-lcs (1.2.5)
18
- extlib (0.9.16)
24
+ docile (1.1.5)
19
25
  faraday (0.8.9)
20
26
  multipart-post (~> 1.2.0)
21
27
  flexmock (1.3.3)
@@ -44,6 +50,8 @@ GEM
44
50
  json (1.8.1)
45
51
  jwt (0.1.11)
46
52
  multi_json (>= 1.5)
53
+ linecache (0.46)
54
+ rbx-require-relative (> 0.0.4)
47
55
  macaddr (1.6.5)
48
56
  systemu (~> 2.6.2)
49
57
  method_source (0.8.2)
@@ -67,28 +75,25 @@ GEM
67
75
  byebug (~> 2.7)
68
76
  pry (~> 0.10)
69
77
  rack (1.5.2)
70
- rake (0.9.6)
78
+ rake (10.3.2)
79
+ rbx-require-relative (0.0.9)
71
80
  rdoc (4.1.1)
72
81
  json (~> 1.4)
73
82
  rest-client (1.6.7)
74
83
  mime-types (>= 1.16)
75
84
  right_aws (3.1.0)
76
85
  right_http_connection (>= 1.2.5)
77
- right_develop (2.3.0)
86
+ right_develop (3.1.4)
78
87
  builder (~> 3.0)
79
- cucumber (~> 1.0, < 1.3.3)
80
- extlib
81
88
  rack
82
- rake (>= 0.8.7, < 0.10)
83
89
  right_aws (>= 2.1.0)
84
- right_git (~> 0.1.0)
85
- right_support (~> 2.0)
86
- rspec (>= 1.3, < 3.0)
90
+ right_git (>= 1.0)
91
+ right_support (>= 2.8.31, < 3.0.0)
87
92
  trollop (>= 1.0, < 3.0)
88
- right_git (0.1.0)
89
- right_support (>= 2.8.10, < 3.0.0)
90
- right_http_connection (1.4.0)
91
- right_support (2.8.24)
93
+ right_git (1.0.1)
94
+ right_support (>= 2.8.10)
95
+ right_http_connection (1.5.0)
96
+ right_support (2.8.32)
92
97
  rspec (2.13.0)
93
98
  rspec-core (~> 2.13.0)
94
99
  rspec-expectations (~> 2.13.0)
@@ -97,34 +102,49 @@ GEM
97
102
  rspec-expectations (2.13.0)
98
103
  diff-lcs (>= 1.1.3, < 2.0)
99
104
  rspec-mocks (2.13.1)
105
+ ruby-debug (0.10.4)
106
+ columnize (>= 0.1)
107
+ ruby-debug-base (~> 0.10.4.0)
108
+ ruby-debug-base (0.10.4)
109
+ linecache (>= 0.3)
100
110
  simple_uuid (0.4.0)
111
+ simplecov (0.9.1)
112
+ docile (~> 1.1.0)
113
+ multi_json (~> 1.0)
114
+ simplecov-html (~> 0.8.0)
115
+ simplecov-html (0.8.0)
101
116
  slop (3.6.0)
102
117
  systemu (2.6.3)
118
+ term-ansicolor (1.3.0)
119
+ tins (~> 1.0)
120
+ thor (0.19.1)
121
+ tins (1.3.3)
103
122
  trollop (2.0)
104
123
  uuid (2.3.7)
105
124
  macaddr (~> 1.0)
106
125
  uuidtools (2.1.4)
107
- yajl-ruby (1.2.0)
108
126
 
109
127
  PLATFORMS
110
128
  ruby
111
129
 
112
130
  DEPENDENCIES
113
131
  addressable (~> 2.2.7)
132
+ coveralls
114
133
  cucumber (~> 1.0, < 1.3.3)
115
134
  flexmock (~> 1.0)
116
135
  iconv
117
136
  jeweler (~> 2.0)
137
+ json (~> 1.8)
118
138
  mime-types (~> 1.0)
119
139
  net-ssh (~> 2.0)
120
140
  nokogiri (~> 1.5.0)
121
141
  pry
122
142
  pry-byebug
123
- rest-client (~> 1.6)
124
- right_develop (~> 2.1)
143
+ rake (~> 10.0)
144
+ rest-client (~> 1.6.7)
145
+ right_develop (~> 3.1)
125
146
  rspec (~> 2.13.0)
126
147
  ruby-debug
127
148
  simple_uuid (~> 0.2)
128
149
  uuid (~> 2.3)
129
150
  uuidtools (~> 2.0)
130
- yajl-ruby (~> 1.1)
@@ -1,10 +1,16 @@
1
- RightSupport is a library of reusable, unit- and functional-tested Ruby code that RightScale has found broadly useful.
1
+ # RightSupport
2
2
 
3
- Maintained by the RightScale Teal Team
3
+ This is a library of reusable, unit- and functional-tested Ruby code that RightScale has found broadly useful.
4
4
 
5
- == What Does It Do?
5
+ [![Build Status](https://travis-ci.org/rightscale/right_support.svg?branch=master)](https://travis-ci.org/rightscale/right_support)
6
6
 
7
- === Logging
7
+ [![Coverage Status](https://img.shields.io/coveralls/rightscale/right_support.svg)](https://coveralls.io/r/rightscale/right_support?branch=master)
8
+
9
+ Maintained by the RightScale Technicolor Team
10
+
11
+ # What Does It Do?
12
+
13
+ ## Logging
8
14
 
9
15
  SystemLogger is a rewrite of the seattle.rb SyslogLogger class that features the following improvements:
10
16
  * Contains several bugfixes vs. SyslogLogger 1.4.0
@@ -26,7 +32,7 @@ loggers!
26
32
  #but MY jet
27
33
  @my_jet.logger = Logger.new(StringIO.new)
28
34
 
29
- ==== Logging for Rack Applications
35
+ ### Logging for Rack Applications
30
36
 
31
37
  RightSupport also provides Rack middleware that allows a Rack app to use any log sink it wishes. The
32
38
  stock Rack logger middleware is inflexible and gives the end user no control over which logger is used
@@ -56,9 +62,9 @@ After that all rack requests to MyApp will be logged, and since we mixed Log::Mi
56
62
 
57
63
  logger.info "Hello world\nThis will appear on separate lines\nand without \e[33;0mbeautiful colors"
58
64
 
59
- === Networking Stuff
65
+ ## Networking Stuff
60
66
 
61
- ==== HTTP Client
67
+ ### HTTP Client
62
68
 
63
69
  We provide a very thin wrapper around the rest-client gem that enables simple but
64
70
  robust rest requests with a timeout, headers, etc.
@@ -80,7 +86,7 @@ optional timeout to be specified as an extra parameter.
80
86
  @client.get('http://localhost/moo', {:query=>{:a=>{:b=>:c}}} )
81
87
  # the url that would be requested is http://localhost/moo?a[b]=c
82
88
 
83
- ==== Client-Side Load Balancer
89
+ ### Client-Side Load Balancer
84
90
 
85
91
  RequestBalancer randomly chooses endpoints for a network request, which lets
86
92
  you perform easy client-side load balancing:
@@ -95,7 +101,7 @@ you perform easy client-side load balancing:
95
101
  The balancer will keep trying requests until one of them succeeds without
96
102
  throwing any exceptions. (NB: a nil return value counts as success!!)
97
103
 
98
- ==== HTTP Request Tracking for Rack
104
+ ### HTTP Request Tracking for Rack
99
105
 
100
106
  Correlate data flows across your entire architecture with the RequestTracker
101
107
  middleware, which uses custom HTTP headers to "tag" every Web request with
@@ -110,7 +116,7 @@ To use this functionality you need:
110
116
 
111
117
  use RightSupport::Rack::RequestTracker
112
118
 
113
- === Statistics Gathering
119
+ ## Statistics Gathering
114
120
 
115
121
  Profile your compute-heavy and network activities using a Stats::Activity counter.
116
122
 
@@ -125,7 +131,7 @@ Profile your compute-heavy and network activities using a Stats::Activity counte
125
131
 
126
132
  puts "Only %.1f lines/sec? You are a slow typist!" % [stats.avg_rate]
127
133
 
128
- === Input Validation
134
+ ## Input Validation
129
135
 
130
136
  Validation contains several format-checkers that can be used to validate your
131
137
  web app's models before saving, check for preconditions in your controllers,
@@ -149,7 +155,7 @@ but does not pollute the dispatch table of your application classes.
149
155
  the_key = STDIN.read
150
156
  raise ArgumentError unless RightSupport::Validation.ssh_public_key?(the_key)
151
157
 
152
- === String Manipulation
158
+ ## String Manipulation
153
159
 
154
160
  StringExtensions contains String#camelize, which is only defined if the
155
161
  ActiveSupport gem cannot be loaded. It also has some RightScale-specific
@@ -160,7 +166,7 @@ methods:
160
166
 
161
167
  Net::StringEncoder applies and removes URL-escape, base64 and other encodings.
162
168
 
163
- === Configuration
169
+ ## Configuration
164
170
 
165
171
  RightSupport::Config contains functionality, which provides possibility
166
172
  to use human-readable yaml configuration files. For example, you have following yaml
data/Rakefile CHANGED
@@ -3,13 +3,21 @@ require 'rubygems'
3
3
  require 'bundler/setup'
4
4
 
5
5
  require 'rake'
6
- require 'rdoc/task'
7
6
  require 'rubygems/package_task'
8
7
 
9
8
  require 'rake/clean'
10
9
  require 'rspec/core/rake_task'
11
10
  require 'cucumber/rake/task'
12
11
 
12
+ # These dependencies can be omitted using "bundle install --without"; tolerate their absence.
13
+ ['rdoc/task', 'jeweler', 'coveralls/rake/task'].each do |optional|
14
+ begin
15
+ require optional
16
+ rescue LoadError
17
+ # ignore
18
+ end
19
+ end
20
+
13
21
  # But, we have a very special need, because OUR Cucumbers need to run with a pristine
14
22
  # environment that isn't polluted by RVM or RubyGems or anyone else, in order to validate
15
23
  # that RightSupport's CI harness doesn't break your app if those gems are unavailable.
@@ -31,34 +39,41 @@ Cucumber::Rake::Task.new do |t|
31
39
  t.cucumber_opts = %w{--color --format pretty}
32
40
  end
33
41
 
34
- desc 'Generate documentation for the right_support gem.'
35
- Rake::RDocTask.new(:rdoc) do |rdoc|
36
- rdoc.rdoc_dir = 'doc'
37
- rdoc.title = 'RightSupport'
38
- rdoc.options << '--line-numbers' << '--inline-source'
39
- rdoc.rdoc_files.include('README.rdoc')
40
- rdoc.rdoc_files.include('lib/**/*.rb')
41
- rdoc.rdoc_files.exclude('features/**/*')
42
- rdoc.rdoc_files.exclude('spec/**/*')
42
+ if defined?(Rake::RDocTask)
43
+ desc 'Generate documentation for the right_support gem.'
44
+ Rake::RDocTask.new(:rdoc) do |rdoc|
45
+ rdoc.rdoc_dir = 'doc'
46
+ rdoc.title = 'RightSupport'
47
+ rdoc.options << '--line-numbers' << '--inline-source'
48
+ rdoc.rdoc_files.include('README.rdoc')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ rdoc.rdoc_files.exclude('features/**/*')
51
+ rdoc.rdoc_files.exclude('spec/**/*')
52
+ end
43
53
  end
44
54
 
45
- require 'jeweler'
46
- tasks = Jeweler::Tasks.new do |gem|
47
- # gem is a Gem::Specification; see http://docs.rubygems.org/read/chapter/20 for more options
48
- gem.name = "right_support"
49
- gem.homepage = "https://github.com/rightscale/right_support"
50
- gem.license = "MIT"
51
- gem.summary = %Q{Reusable foundation code.}
52
- gem.description = %Q{A toolkit of useful, reusable foundation code created by RightScale.}
53
- gem.email = "support@rightscale.com"
54
- gem.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Alexey Karpik', 'Scott Messier']
55
- end
55
+ if defined?(Jeweler)
56
+ tasks = Jeweler::Tasks.new do |gem|
57
+ # gem is a Gem::Specification; see http://docs.rubygems.org/read/chapter/20 for more options
58
+ gem.name = "right_support"
59
+ gem.homepage = "https://github.com/rightscale/right_support"
60
+ gem.license = "MIT"
61
+ gem.summary = %Q{Reusable foundation code.}
62
+ gem.description = %Q{A toolkit of useful, reusable foundation code created by RightScale.}
63
+ gem.email = "support@rightscale.com"
64
+ gem.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff', 'Alexey Karpik', 'Scott Messier']
65
+ end
56
66
 
57
- # Never auto-commit during operations that change the repository. Allows developers to decide on their own commit comment
58
- # and/or aggregate version bumps into other fixes.
59
- tasks.jeweler.commit = false
67
+ # Never auto-commit during operations that change the repository. Allows developers to decide on their own commit comment
68
+ # and/or aggregate version bumps into other fixes.
69
+ tasks.jeweler.commit = false
60
70
 
61
- Jeweler::RubygemsDotOrgTasks.new
71
+ Jeweler::RubygemsDotOrgTasks.new
72
+ end
73
+
74
+ if defined?(Coveralls)
75
+ Coveralls::RakeTask.new
76
+ end
62
77
 
63
78
  CLEAN.include('pkg')
64
79
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.8.32
1
+ 2.8.33
@@ -33,7 +33,7 @@ Feature: JSON serialization
33
33
 
34
34
  Scenario: invalid UTF-8 characters
35
35
  When I serialize the Ruby value: "\xC0\xBCscript>\xC0\xBC/script>"
36
- Then the serialized value should be: "??script>??/script>"
36
+ Then the serialized value should have no invalid characters
37
37
 
38
38
  Scenario: valid UTF-8 characters
39
39
  When I serialize the Ruby value: "onê"
@@ -77,6 +77,24 @@ Then /^the serialized value should round-trip cleanly$/ do
77
77
  end
78
78
  end
79
79
 
80
+ Then /^the serialized value should have no invalid characters$/ do
81
+ if @serialized_value.respond_to?(:valid_encoding?)
82
+ # modern Rubies
83
+ @serialized_value.valid_encoding?.should be_true
84
+ else
85
+ # Ruby 1.8
86
+ raised = false
87
+ begin
88
+ iconv = Iconv.new('UTF-8', 'UTF-8')
89
+ iconv.iconv(@serialized_value)
90
+ rescue Exception => e
91
+ raised = true
92
+ end
93
+
94
+ raised.should be_false
95
+ end
96
+ end
97
+
80
98
  When /^the serialized value should fail to round\-trip$/ do
81
99
  @serializer.load(@serialized_value).should_not == @ruby_value
82
100
  end
@@ -26,6 +26,8 @@ require 'tmpdir'
26
26
  require 'rubygems'
27
27
  require 'bundler/setup'
28
28
 
29
+ require 'simplecov'
30
+
29
31
  $:.unshift(File.expand_path('../../../lib', __FILE__)) #ensure we load THIS project's code, not an installed gem
30
32
  require 'right_support'
31
33
  require 'right_support/ci'
@@ -24,6 +24,7 @@
24
24
  # RightSupport's main file. Make up for Cucumber's shortcomings.
25
25
  require 'right_support'
26
26
 
27
+ # :nocov:
27
28
  module RightSupport::CI
28
29
  if require_succeeds?('cucumber/formatter/junit')
29
30
  # @deprecated Please do not use this class
@@ -57,3 +58,4 @@ module RightSupport::CI
57
58
  end
58
59
  end
59
60
  end
61
+ # :nocov:
@@ -22,6 +22,7 @@
22
22
 
23
23
  require 'time'
24
24
 
25
+ # :nocov:
25
26
  module RightSupport::CI
26
27
  if require_succeeds?('spec/runner/formatter/base_text_formatter')
27
28
  # RSpec 1.x
@@ -194,3 +195,4 @@ module RightSupport::CI
194
195
  end
195
196
  end
196
197
  end
198
+ # :nocov:
@@ -25,6 +25,7 @@ require 'rake/tasklib'
25
25
  # required directly.
26
26
  require 'right_support'
27
27
 
28
+ # :nocov:
28
29
  module RightSupport::CI
29
30
  # A Rake task definition that creates a CI namespace with appropriate
30
31
  # tests.
@@ -88,3 +89,4 @@ module RightSupport::CI
88
89
  end
89
90
  end
90
91
  end
92
+ # :nocov:
@@ -163,9 +163,11 @@ module RightSupport::Data
163
163
  # Nothing to do
164
164
  dirty
165
165
  else
166
- # Some other encoding, or string has invalid characters. Scrub, and possibly lose
167
- # data in the process
168
- dirty.dup.encode(Encoding::UTF_8,
166
+ # String has encoding other than UTF-8, or has invalid UTF-8 characters. Force the
167
+ # encoding to binary (if it's already UTF-8) to ensure that transcoding occurs,
168
+ # then transcode to UTF-8 and replace invalid characters with a question mark.
169
+ dirty.force_encoding(Encoding::BINARY) if dirty.encoding == Encoding::UTF_8
170
+ dirty.encode(Encoding::UTF_8,
169
171
  :invalid => :replace,
170
172
  :undef => :replace,
171
173
  :replace => '?')
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright (c) 2007, 2008, 2009, 2010, 2011, 2012 Christian Neukirchen <purl.org/net/chneukirchen>
3
+ # Copyright (c) 2014 RightScale Inc
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ # Copied and modified from
25
+ # https://github.com/rack/rack/blob/master/lib/rack/runtime.rb
26
+ module RightSupport::Rack
27
+ # Sets an "X-Runtime" response header, indicating the response
28
+ # time of the request, in milliseconds
29
+ #
30
+ # You can put it right before the application to see the processing
31
+ # time, or before all the other middlewares to include time for them,
32
+ # too.
33
+ class Runtime
34
+ def initialize(app, name = nil)
35
+ @app = app
36
+ @header_name = "X-Runtime"
37
+ @header_name << "-#{name}" if name
38
+ end
39
+
40
+ def call(env)
41
+ start_time = Time.now
42
+ status, headers, body = @app.call(env)
43
+ request_time = Time.now - start_time
44
+
45
+ if !headers.has_key?(@header_name)
46
+ headers[@header_name] = (request_time * 1000).truncate.to_s
47
+ end
48
+
49
+ [status, headers, body]
50
+ end
51
+ end
52
+ end
@@ -32,3 +32,4 @@ end
32
32
  require 'right_support/rack/log_setter'
33
33
  require 'right_support/rack/request_logger'
34
34
  require 'right_support/rack/request_tracker'
35
+ require 'right_support/rack/runtime'
@@ -2,29 +2,32 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: right_support 2.8.32 ruby lib
5
+ # stub: right_support 2.8.33 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "right_support"
9
- s.version = "2.8.32"
9
+ s.version = "2.8.33"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Tony Spataro", "Sergey Sergyenko", "Ryan Williamson", "Lee Kirchhoff", "Alexey Karpik", "Scott Messier"]
14
- s.date = "2014-09-30"
14
+ s.date = "2014-10-18"
15
15
  s.description = "A toolkit of useful, reusable foundation code created by RightScale."
16
16
  s.email = "support@rightscale.com"
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.rdoc"
19
+ "README.md"
20
20
  ]
21
21
  s.files = [
22
+ ".coveralls.yml",
22
23
  ".rspec",
24
+ ".simplecov",
25
+ ".travis.yml",
23
26
  "CHANGELOG.rdoc",
24
27
  "Gemfile",
25
28
  "Gemfile.lock",
26
29
  "LICENSE",
27
- "README.rdoc",
30
+ "README.md",
28
31
  "Rakefile",
29
32
  "VERSION",
30
33
  "features/balancer_error_handling.feature",
@@ -85,6 +88,7 @@ Gem::Specification.new do |s|
85
88
  "lib/right_support/rack/log_setter.rb",
86
89
  "lib/right_support/rack/request_logger.rb",
87
90
  "lib/right_support/rack/request_tracker.rb",
91
+ "lib/right_support/rack/runtime.rb",
88
92
  "lib/right_support/ruby.rb",
89
93
  "lib/right_support/ruby/easy_singleton.rb",
90
94
  "lib/right_support/ruby/object_extensions.rb",
@@ -131,6 +135,7 @@ Gem::Specification.new do |s|
131
135
  "spec/rack/log_setter_spec.rb",
132
136
  "spec/rack/request_logger_spec.rb",
133
137
  "spec/rack/request_tracker_spec.rb",
138
+ "spec/rack/runtime_spec.rb",
134
139
  "spec/ruby/easy_singleton_spec.rb",
135
140
  "spec/ruby/object_extensions_spec.rb",
136
141
  "spec/ruby/string_extensions_spec.rb",
@@ -150,15 +155,21 @@ Gem::Specification.new do |s|
150
155
  s.specification_version = 4
151
156
 
152
157
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
158
+ s.add_development_dependency(%q<rake>, ["~> 10.0"])
159
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
153
160
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
154
161
  s.add_development_dependency(%q<pry>, [">= 0"])
155
162
  s.add_development_dependency(%q<pry-byebug>, [">= 0"])
156
163
  else
164
+ s.add_dependency(%q<rake>, ["~> 10.0"])
165
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
157
166
  s.add_dependency(%q<ruby-debug>, [">= 0"])
158
167
  s.add_dependency(%q<pry>, [">= 0"])
159
168
  s.add_dependency(%q<pry-byebug>, [">= 0"])
160
169
  end
161
170
  else
171
+ s.add_dependency(%q<rake>, ["~> 10.0"])
172
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
162
173
  s.add_dependency(%q<ruby-debug>, [">= 0"])
163
174
  s.add_dependency(%q<pry>, [">= 0"])
164
175
  s.add_dependency(%q<pry-byebug>, [">= 0"])
@@ -220,8 +220,17 @@ describe RightSupport::Data::HashTools do
220
220
  {
221
221
  :empty => {},
222
222
  :shallow => { :x => 1, :y => 2 },
223
- :deep => { :x => 1, :y => { :a => 'A' }, :z => { :b => 'B', :c => { :foo => :bar } } },
224
- :arrayed => [ { :x => 1 }, { :y => { :a => 'A' } }, :z => { :b => 'B', :c => { :foo => :bar } } ],
223
+ :deep => {
224
+ :x => 1,
225
+ :y => { :a => 'A' },
226
+ :z => { :b => 'B',
227
+ :c => { :foo => :bar } } },
228
+ :arrayed => [
229
+ { :x => 1 },
230
+ { :y => { :a => 'A' } },
231
+ { :z => { :b => 'B',
232
+ :c => { :foo => :bar } } }
233
+ ],
225
234
  :duplicable => {
226
235
  :tree => {
227
236
  :branch => {
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ class FasterApp
4
+ def self.call(env)
5
+ sleep 0.05; [200, {}, "50ms"]
6
+ end
7
+ end
8
+
9
+ class SlowerApp
10
+ def self.call(env)
11
+ sleep 0.2; [200, {}, "200ms"]
12
+ end
13
+ end
14
+
15
+ describe RightSupport::Rack::Runtime do
16
+ before(:each) do
17
+ @app = flexmock('Rack app')
18
+ @app.should_receive(:call).and_return([200, {}, 'body']).by_default
19
+ @env = {'rack.logger' => @logger}
20
+ @middleware = RightSupport::Rack::Runtime.new(@app)
21
+ end
22
+
23
+ context :call do
24
+ it 'sets an X-Runtime header in response' do
25
+ @middleware.call(@env).should == [200, {"X-Runtime"=>"0"}, 'body']
26
+ end
27
+
28
+ it 'sets a correct X-Runtime value for 50 ms app' do
29
+ faster = RightSupport::Rack::Runtime.new(FasterApp)
30
+ result = faster.call(@env)
31
+ result[1].keys.should == ['X-Runtime']
32
+ result[1]['X-Runtime'].to_i.should >= 50
33
+ result[1]['X-Runtime'].to_i.should < 70
34
+ end
35
+
36
+ it 'sets a correct X-Runtime value for 200 ms app' do
37
+ slower = RightSupport::Rack::Runtime.new(SlowerApp)
38
+ result = slower.call(@env)
39
+ result[1].keys.should == ['X-Runtime']
40
+ result[1]['X-Runtime'].to_i.should >= 200
41
+ result[1]['X-Runtime'].to_i.should < 270
42
+ end
43
+
44
+ it 'allows appending custom name to X-Runtime header' do
45
+ customized = RightSupport::Rack::Runtime.new(@app, "Test")
46
+ customized.call(@env).should == [200, {"X-Runtime-Test"=>"0"}, 'body']
47
+ end
48
+ end
49
+ end
data/spec/spec_helper.rb CHANGED
@@ -23,6 +23,8 @@ require 'rubygems'
23
23
  require 'bundler/setup'
24
24
  require 'flexmock'
25
25
 
26
+ require 'simplecov'
27
+
26
28
  $:.unshift(File.expand_path('../../../lib', __FILE__)) #ensure we load THIS project's code, not an installed gem
27
29
  require 'right_support'
28
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.32
4
+ version: 2.8.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Spataro
@@ -13,8 +13,36 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2014-09-30 00:00:00.000000000 Z
16
+ date: 2014-10-18 00:00:00.000000000 Z
17
17
  dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: rake
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - "~>"
23
+ - !ruby/object:Gem::Version
24
+ version: '10.0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '10.0'
32
+ - !ruby/object:Gem::Dependency
33
+ name: jeweler
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
18
46
  - !ruby/object:Gem::Dependency
19
47
  name: ruby-debug
20
48
  requirement: !ruby/object:Gem::Requirement
@@ -63,14 +91,17 @@ executables: []
63
91
  extensions: []
64
92
  extra_rdoc_files:
65
93
  - LICENSE
66
- - README.rdoc
94
+ - README.md
67
95
  files:
96
+ - ".coveralls.yml"
68
97
  - ".rspec"
98
+ - ".simplecov"
99
+ - ".travis.yml"
69
100
  - CHANGELOG.rdoc
70
101
  - Gemfile
71
102
  - Gemfile.lock
72
103
  - LICENSE
73
- - README.rdoc
104
+ - README.md
74
105
  - Rakefile
75
106
  - VERSION
76
107
  - features/balancer_error_handling.feature
@@ -131,6 +162,7 @@ files:
131
162
  - lib/right_support/rack/log_setter.rb
132
163
  - lib/right_support/rack/request_logger.rb
133
164
  - lib/right_support/rack/request_tracker.rb
165
+ - lib/right_support/rack/runtime.rb
134
166
  - lib/right_support/ruby.rb
135
167
  - lib/right_support/ruby/easy_singleton.rb
136
168
  - lib/right_support/ruby/object_extensions.rb
@@ -177,6 +209,7 @@ files:
177
209
  - spec/rack/log_setter_spec.rb
178
210
  - spec/rack/request_logger_spec.rb
179
211
  - spec/rack/request_tracker_spec.rb
212
+ - spec/rack/runtime_spec.rb
180
213
  - spec/ruby/easy_singleton_spec.rb
181
214
  - spec/ruby/object_extensions_spec.rb
182
215
  - spec/ruby/string_extensions_spec.rb