scout 5.7.1 → 5.7.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/CHANGELOG.markdown +5 -0
  2. data/lib/scout/command/run.rb +1 -1
  3. data/lib/scout/server.rb +2 -1
  4. data/lib/scout/streamer.rb +3 -2
  5. data/lib/scout/streamer_daemon.rb +4 -4
  6. data/lib/scout/version.rb +1 -1
  7. data/test/scout_test.rb +7 -8
  8. data/vendor/httpclient/README.txt +759 -0
  9. data/vendor/httpclient/bin/httpclient +65 -0
  10. data/vendor/httpclient/lib/hexdump.rb +50 -0
  11. data/vendor/httpclient/lib/http-access2.rb +55 -0
  12. data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
  13. data/vendor/httpclient/lib/http-access2/http.rb +1 -0
  14. data/vendor/httpclient/lib/httpclient.rb +1156 -0
  15. data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
  16. data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
  17. data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
  18. data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
  19. data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
  20. data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
  21. data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
  22. data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
  23. data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
  24. data/vendor/httpclient/lib/httpclient/util.rb +178 -0
  25. data/vendor/httpclient/lib/httpclient/version.rb +3 -0
  26. data/vendor/httpclient/lib/oauthclient.rb +110 -0
  27. data/vendor/httpclient/sample/async.rb +8 -0
  28. data/vendor/httpclient/sample/auth.rb +11 -0
  29. data/vendor/httpclient/sample/cookie.rb +18 -0
  30. data/vendor/httpclient/sample/dav.rb +103 -0
  31. data/vendor/httpclient/sample/howto.rb +49 -0
  32. data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
  33. data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
  34. data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
  35. data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
  36. data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
  37. data/vendor/httpclient/sample/ssl/0key.pem +30 -0
  38. data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
  39. data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
  40. data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
  41. data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
  42. data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
  43. data/vendor/httpclient/sample/stream.rb +21 -0
  44. data/vendor/httpclient/sample/thread.rb +27 -0
  45. data/vendor/httpclient/sample/wcat.rb +21 -0
  46. data/vendor/httpclient/test/ca-chain.cert +44 -0
  47. data/vendor/httpclient/test/ca.cert +23 -0
  48. data/vendor/httpclient/test/client.cert +19 -0
  49. data/vendor/httpclient/test/client.key +15 -0
  50. data/vendor/httpclient/test/helper.rb +129 -0
  51. data/vendor/httpclient/test/htdigest +1 -0
  52. data/vendor/httpclient/test/htpasswd +2 -0
  53. data/vendor/httpclient/test/runner.rb +2 -0
  54. data/vendor/httpclient/test/server.cert +19 -0
  55. data/vendor/httpclient/test/server.key +15 -0
  56. data/vendor/httpclient/test/sslsvr.rb +65 -0
  57. data/vendor/httpclient/test/subca.cert +21 -0
  58. data/vendor/httpclient/test/test_auth.rb +321 -0
  59. data/vendor/httpclient/test/test_cookie.rb +391 -0
  60. data/vendor/httpclient/test/test_hexdump.rb +14 -0
  61. data/vendor/httpclient/test/test_http-access2.rb +507 -0
  62. data/vendor/httpclient/test/test_httpclient.rb +1783 -0
  63. data/vendor/httpclient/test/test_include_client.rb +52 -0
  64. data/vendor/httpclient/test/test_ssl.rb +235 -0
  65. data/vendor/multi_json/.document +5 -0
  66. data/vendor/multi_json/.rspec +3 -0
  67. data/vendor/multi_json/.travis.yml +11 -0
  68. data/vendor/multi_json/.yardopts +6 -0
  69. data/vendor/multi_json/CHANGELOG.md +169 -0
  70. data/vendor/multi_json/CONTRIBUTING.md +46 -0
  71. data/vendor/multi_json/Gemfile +31 -0
  72. data/vendor/multi_json/LICENSE.md +20 -0
  73. data/vendor/multi_json/README.md +109 -0
  74. data/vendor/multi_json/Rakefile +12 -0
  75. data/vendor/multi_json/lib/multi_json.rb +157 -0
  76. data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
  77. data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
  78. data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
  79. data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
  80. data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
  81. data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
  82. data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
  83. data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
  84. data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
  85. data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
  86. data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
  87. data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
  88. data/vendor/multi_json/lib/multi_json/options.rb +48 -0
  89. data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
  90. data/vendor/multi_json/lib/multi_json/version.rb +20 -0
  91. data/vendor/multi_json/multi_json.gemspec +22 -0
  92. data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
  93. data/vendor/multi_json/spec/has_options.rb +119 -0
  94. data/vendor/multi_json/spec/helper.rb +35 -0
  95. data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
  96. data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
  97. data/vendor/{signature → pusher}/.document +0 -0
  98. data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
  99. data/vendor/pusher/.gitignore +23 -0
  100. data/vendor/pusher/.travis.yml +15 -0
  101. data/vendor/pusher/Gemfile +2 -0
  102. data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
  103. data/vendor/pusher/README.md +186 -0
  104. data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
  105. data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
  106. data/vendor/pusher/lib/pusher.rb +60 -0
  107. data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
  108. data/vendor/pusher/lib/pusher/client.rb +306 -0
  109. data/vendor/pusher/lib/pusher/request.rb +107 -0
  110. data/vendor/pusher/lib/pusher/resource.rb +36 -0
  111. data/vendor/pusher/lib/pusher/webhook.rb +110 -0
  112. data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
  113. data/vendor/pusher/spec/channel_spec.rb +127 -0
  114. data/vendor/pusher/spec/client_spec.rb +464 -0
  115. data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
  116. data/vendor/pusher/spec/web_hook_spec.rb +117 -0
  117. data/vendor/signature/.travis.yml +15 -0
  118. data/vendor/signature/Gemfile +1 -1
  119. data/vendor/signature/README.md +38 -28
  120. data/vendor/signature/lib/signature.rb +97 -15
  121. data/vendor/signature/lib/signature/query_encoder.rb +47 -0
  122. data/vendor/signature/lib/signature/version.rb +1 -1
  123. data/vendor/signature/signature.gemspec +3 -2
  124. data/vendor/signature/spec/signature_spec.rb +164 -55
  125. data/vendor/signature/spec/spec_helper.rb +2 -3
  126. metadata +120 -145
  127. data/vendor/json_pure/.gitignore +0 -12
  128. data/vendor/json_pure/.travis.yml +0 -20
  129. data/vendor/json_pure/CHANGES +0 -282
  130. data/vendor/json_pure/COPYING +0 -58
  131. data/vendor/json_pure/COPYING-json-jruby +0 -57
  132. data/vendor/json_pure/GPL +0 -340
  133. data/vendor/json_pure/Gemfile +0 -11
  134. data/vendor/json_pure/README-json-jruby.markdown +0 -33
  135. data/vendor/json_pure/README.rdoc +0 -358
  136. data/vendor/json_pure/Rakefile +0 -412
  137. data/vendor/json_pure/TODO +0 -1
  138. data/vendor/json_pure/VERSION +0 -1
  139. data/vendor/json_pure/data/example.json +0 -1
  140. data/vendor/json_pure/data/index.html +0 -38
  141. data/vendor/json_pure/data/prototype.js +0 -4184
  142. data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
  143. data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
  144. data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
  145. data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
  146. data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
  147. data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
  148. data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
  149. data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
  150. data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
  151. data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
  152. data/vendor/json_pure/install.rb +0 -23
  153. data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
  154. data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
  155. data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
  156. data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
  157. data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
  158. data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
  159. data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
  160. data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
  161. data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
  162. data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
  163. data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
  164. data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
  165. data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
  166. data/vendor/json_pure/json-java.gemspec +0 -23
  167. data/vendor/json_pure/json.gemspec +0 -37
  168. data/vendor/json_pure/json_pure.gemspec +0 -39
  169. data/vendor/json_pure/lib/json.rb +0 -62
  170. data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
  171. data/vendor/json_pure/lib/json/add/complex.rb +0 -22
  172. data/vendor/json_pure/lib/json/add/core.rb +0 -11
  173. data/vendor/json_pure/lib/json/add/date.rb +0 -34
  174. data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
  175. data/vendor/json_pure/lib/json/add/exception.rb +0 -31
  176. data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
  177. data/vendor/json_pure/lib/json/add/range.rb +0 -29
  178. data/vendor/json_pure/lib/json/add/rational.rb +0 -22
  179. data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
  180. data/vendor/json_pure/lib/json/add/struct.rb +0 -30
  181. data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
  182. data/vendor/json_pure/lib/json/add/time.rb +0 -38
  183. data/vendor/json_pure/lib/json/common.rb +0 -487
  184. data/vendor/json_pure/lib/json/ext.rb +0 -21
  185. data/vendor/json_pure/lib/json/ext/.keep +0 -0
  186. data/vendor/json_pure/lib/json/generic_object.rb +0 -70
  187. data/vendor/json_pure/lib/json/pure.rb +0 -21
  188. data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
  189. data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
  190. data/vendor/json_pure/lib/json/version.rb +0 -8
  191. data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
  192. data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
  193. data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
  194. data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
  195. data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
  196. data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
  197. data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
  198. data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
  199. data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
  200. data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
  201. data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
  202. data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
  203. data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
  204. data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
  205. data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
  206. data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
  207. data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
  208. data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
  209. data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
  210. data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
  211. data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
  212. data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
  213. data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
  214. data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
  215. data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
  216. data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
  217. data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
  218. data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
  219. data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
  220. data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
  221. data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
  222. data/vendor/json_pure/tests/setup_variant.rb +0 -11
  223. data/vendor/json_pure/tests/test_json.rb +0 -545
  224. data/vendor/json_pure/tests/test_json_addition.rb +0 -196
  225. data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
  226. data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
  227. data/vendor/json_pure/tests/test_json_generate.rb +0 -322
  228. data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
  229. data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
  230. data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
  231. data/vendor/json_pure/tools/fuzz.rb +0 -139
  232. data/vendor/json_pure/tools/server.rb +0 -62
  233. data/vendor/pusher-gem/Gemfile +0 -2
  234. data/vendor/pusher-gem/README.md +0 -80
  235. data/vendor/pusher-gem/lib/pusher.rb +0 -107
  236. data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
  237. data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
  238. data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
  239. data/vendor/ruby-hmac/History.txt +0 -15
  240. data/vendor/ruby-hmac/Manifest.txt +0 -11
  241. data/vendor/ruby-hmac/README.md +0 -41
  242. data/vendor/ruby-hmac/Rakefile +0 -23
  243. data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
  244. data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
  245. data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
  246. data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
  247. data/vendor/ruby-hmac/lib/hmac.rb +0 -118
  248. data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
  249. data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
  250. data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
  251. data/vendor/signature/VERSION +0 -1
@@ -1,30 +0,0 @@
1
- unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
- require 'json'
3
- end
4
-
5
- # Struct serialization/deserialization
6
- class Struct
7
-
8
- # Deserializes JSON string by constructing new Struct object with values
9
- # <tt>v</tt> serialized by <tt>to_json</tt>.
10
- def self.json_create(object)
11
- new(*object['v'])
12
- end
13
-
14
- # Returns a hash, that will be turned into a JSON object and represent this
15
- # object.
16
- def as_json(*)
17
- klass = self.class.name
18
- klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
19
- {
20
- JSON.create_id => klass,
21
- 'v' => values,
22
- }
23
- end
24
-
25
- # Stores class name (Struct) with Struct values <tt>v</tt> as a JSON string.
26
- # Only named structs are supported.
27
- def to_json(*args)
28
- as_json.to_json(*args)
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
- require 'json'
3
- end
4
-
5
- # Symbol serialization/deserialization
6
- class Symbol
7
- # Returns a hash, that will be turned into a JSON object and represent this
8
- # object.
9
- def as_json(*)
10
- {
11
- JSON.create_id => self.class.name,
12
- 's' => to_s,
13
- }
14
- end
15
-
16
- # Stores class name (Symbol) with String representation of Symbol as a JSON string.
17
- def to_json(*a)
18
- as_json.to_json(*a)
19
- end
20
-
21
- # Deserializes JSON string by converting the <tt>string</tt> value stored in the object to a Symbol
22
- def self.json_create(o)
23
- o['s'].to_sym
24
- end
25
- end
@@ -1,38 +0,0 @@
1
- unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
2
- require 'json'
3
- end
4
-
5
- # Time serialization/deserialization
6
- class Time
7
-
8
- # Deserializes JSON string by converting time since epoch to Time
9
- def self.json_create(object)
10
- if usec = object.delete('u') # used to be tv_usec -> tv_nsec
11
- object['n'] = usec * 1000
12
- end
13
- if instance_methods.include?(:tv_nsec)
14
- at(object['s'], Rational(object['n'], 1000))
15
- else
16
- at(object['s'], object['n'] / 1000)
17
- end
18
- end
19
-
20
- # Returns a hash, that will be turned into a JSON object and represent this
21
- # object.
22
- def as_json(*)
23
- nanoseconds = [ tv_usec * 1000 ]
24
- respond_to?(:tv_nsec) and nanoseconds << tv_nsec
25
- nanoseconds = nanoseconds.max
26
- {
27
- JSON.create_id => self.class.name,
28
- 's' => tv_sec,
29
- 'n' => nanoseconds,
30
- }
31
- end
32
-
33
- # Stores class name (Time) with number of seconds since epoch and number of
34
- # microseconds for Time as JSON string
35
- def to_json(*args)
36
- as_json.to_json(*args)
37
- end
38
- end
@@ -1,487 +0,0 @@
1
- require 'json/version'
2
- require 'json/generic_object'
3
-
4
- module JSON
5
- class << self
6
- # If _object_ is string-like, parse the string and return the parsed result
7
- # as a Ruby data structure. Otherwise generate a JSON text from the Ruby
8
- # data structure object and return it.
9
- #
10
- # The _opts_ argument is passed through to generate/parse respectively. See
11
- # generate and parse for their documentation.
12
- def [](object, opts = {})
13
- if object.respond_to? :to_str
14
- JSON.parse(object.to_str, opts)
15
- else
16
- JSON.generate(object, opts)
17
- end
18
- end
19
-
20
- # Returns the JSON parser class that is used by JSON. This is either
21
- # JSON::Ext::Parser or JSON::Pure::Parser.
22
- attr_reader :parser
23
-
24
- # Set the JSON parser class _parser_ to be used by JSON.
25
- def parser=(parser) # :nodoc:
26
- @parser = parser
27
- remove_const :Parser if JSON.const_defined_in?(self, :Parser)
28
- const_set :Parser, parser
29
- end
30
-
31
- # Return the constant located at _path_. The format of _path_ has to be
32
- # either ::A::B::C or A::B::C. In any case, A has to be located at the top
33
- # level (absolute namespace path?). If there doesn't exist a constant at
34
- # the given path, an ArgumentError is raised.
35
- def deep_const_get(path) # :nodoc:
36
- path.to_s.split(/::/).inject(Object) do |p, c|
37
- case
38
- when c.empty? then p
39
- when JSON.const_defined_in?(p, c) then p.const_get(c)
40
- else
41
- begin
42
- p.const_missing(c)
43
- rescue NameError => e
44
- raise ArgumentError, "can't get const #{path}: #{e}"
45
- end
46
- end
47
- end
48
- end
49
-
50
- # Set the module _generator_ to be used by JSON.
51
- def generator=(generator) # :nodoc:
52
- old, $VERBOSE = $VERBOSE, nil
53
- @generator = generator
54
- generator_methods = generator::GeneratorMethods
55
- for const in generator_methods.constants
56
- klass = deep_const_get(const)
57
- modul = generator_methods.const_get(const)
58
- klass.class_eval do
59
- instance_methods(false).each do |m|
60
- m.to_s == 'to_json' and remove_method m
61
- end
62
- include modul
63
- end
64
- end
65
- self.state = generator::State
66
- const_set :State, self.state
67
- const_set :SAFE_STATE_PROTOTYPE, State.new
68
- const_set :FAST_STATE_PROTOTYPE, State.new(
69
- :indent => '',
70
- :space => '',
71
- :object_nl => "",
72
- :array_nl => "",
73
- :max_nesting => false
74
- )
75
- const_set :PRETTY_STATE_PROTOTYPE, State.new(
76
- :indent => ' ',
77
- :space => ' ',
78
- :object_nl => "\n",
79
- :array_nl => "\n"
80
- )
81
- ensure
82
- $VERBOSE = old
83
- end
84
-
85
- # Returns the JSON generator module that is used by JSON. This is
86
- # either JSON::Ext::Generator or JSON::Pure::Generator.
87
- attr_reader :generator
88
-
89
- # Returns the JSON generator state class that is used by JSON. This is
90
- # either JSON::Ext::Generator::State or JSON::Pure::Generator::State.
91
- attr_accessor :state
92
-
93
- # This is create identifier, which is used to decide if the _json_create_
94
- # hook of a class should be called. It defaults to 'json_class'.
95
- attr_accessor :create_id
96
- end
97
- self.create_id = 'json_class'
98
-
99
- NaN = 0.0/0
100
-
101
- Infinity = 1.0/0
102
-
103
- MinusInfinity = -Infinity
104
-
105
- # The base exception for JSON errors.
106
- class JSONError < StandardError
107
- def self.wrap(exception)
108
- obj = new("Wrapped(#{exception.class}): #{exception.message.inspect}")
109
- obj.set_backtrace exception.backtrace
110
- obj
111
- end
112
- end
113
-
114
- # This exception is raised if a parser error occurs.
115
- class ParserError < JSONError; end
116
-
117
- # This exception is raised if the nesting of parsed data structures is too
118
- # deep.
119
- class NestingError < ParserError; end
120
-
121
- # :stopdoc:
122
- class CircularDatastructure < NestingError; end
123
- # :startdoc:
124
-
125
- # This exception is raised if a generator or unparser error occurs.
126
- class GeneratorError < JSONError; end
127
- # For backwards compatibility
128
- UnparserError = GeneratorError
129
-
130
- # This exception is raised if the required unicode support is missing on the
131
- # system. Usually this means that the iconv library is not installed.
132
- class MissingUnicodeSupport < JSONError; end
133
-
134
- module_function
135
-
136
- # Parse the JSON document _source_ into a Ruby data structure and return it.
137
- #
138
- # _opts_ can have the following
139
- # keys:
140
- # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
141
- # structures. Disable depth checking with :max_nesting => false. It defaults
142
- # to 100.
143
- # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
144
- # defiance of RFC 4627 to be parsed by the Parser. This option defaults
145
- # to false.
146
- # * *symbolize_names*: If set to true, returns symbols for the names
147
- # (keys) in a JSON object. Otherwise strings are returned. Strings are
148
- # the default.
149
- # * *create_additions*: If set to false, the Parser doesn't create
150
- # additions even if a matching class and create_id was found. This option
151
- # defaults to true.
152
- # * *object_class*: Defaults to Hash
153
- # * *array_class*: Defaults to Array
154
- def parse(source, opts = {})
155
- Parser.new(source, opts).parse
156
- end
157
-
158
- # Parse the JSON document _source_ into a Ruby data structure and return it.
159
- # The bang version of the parse method defaults to the more dangerous values
160
- # for the _opts_ hash, so be sure only to parse trusted _source_ documents.
161
- #
162
- # _opts_ can have the following keys:
163
- # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
164
- # structures. Enable depth checking with :max_nesting => anInteger. The parse!
165
- # methods defaults to not doing max depth checking: This can be dangerous
166
- # if someone wants to fill up your stack.
167
- # * *allow_nan*: If set to true, allow NaN, Infinity, and -Infinity in
168
- # defiance of RFC 4627 to be parsed by the Parser. This option defaults
169
- # to true.
170
- # * *create_additions*: If set to false, the Parser doesn't create
171
- # additions even if a matching class and create_id was found. This option
172
- # defaults to true.
173
- def parse!(source, opts = {})
174
- opts = {
175
- :max_nesting => false,
176
- :allow_nan => true
177
- }.update(opts)
178
- Parser.new(source, opts).parse
179
- end
180
-
181
- # Generate a JSON document from the Ruby data structure _obj_ and return
182
- # it. _state_ is * a JSON::State object,
183
- # * or a Hash like object (responding to to_hash),
184
- # * an object convertible into a hash by a to_h method,
185
- # that is used as or to configure a State object.
186
- #
187
- # It defaults to a state object, that creates the shortest possible JSON text
188
- # in one line, checks for circular data structures and doesn't allow NaN,
189
- # Infinity, and -Infinity.
190
- #
191
- # A _state_ hash can have the following keys:
192
- # * *indent*: a string used to indent levels (default: ''),
193
- # * *space*: a string that is put after, a : or , delimiter (default: ''),
194
- # * *space_before*: a string that is put before a : pair delimiter (default: ''),
195
- # * *object_nl*: a string that is put at the end of a JSON object (default: ''),
196
- # * *array_nl*: a string that is put at the end of a JSON array (default: ''),
197
- # * *allow_nan*: true if NaN, Infinity, and -Infinity should be
198
- # generated, otherwise an exception is thrown if these values are
199
- # encountered. This options defaults to false.
200
- # * *max_nesting*: The maximum depth of nesting allowed in the data
201
- # structures from which JSON is to be generated. Disable depth checking
202
- # with :max_nesting => false, it defaults to 100.
203
- #
204
- # See also the fast_generate for the fastest creation method with the least
205
- # amount of sanity checks, and the pretty_generate method for some
206
- # defaults for pretty output.
207
- def generate(obj, opts = nil)
208
- if State === opts
209
- state, opts = opts, nil
210
- else
211
- state = SAFE_STATE_PROTOTYPE.dup
212
- end
213
- if opts
214
- if opts.respond_to? :to_hash
215
- opts = opts.to_hash
216
- elsif opts.respond_to? :to_h
217
- opts = opts.to_h
218
- else
219
- raise TypeError, "can't convert #{opts.class} into Hash"
220
- end
221
- state = state.configure(opts)
222
- end
223
- state.generate(obj)
224
- end
225
-
226
- # :stopdoc:
227
- # I want to deprecate these later, so I'll first be silent about them, and
228
- # later delete them.
229
- alias unparse generate
230
- module_function :unparse
231
- # :startdoc:
232
-
233
- # Generate a JSON document from the Ruby data structure _obj_ and return it.
234
- # This method disables the checks for circles in Ruby objects.
235
- #
236
- # *WARNING*: Be careful not to pass any Ruby data structures with circles as
237
- # _obj_ argument because this will cause JSON to go into an infinite loop.
238
- def fast_generate(obj, opts = nil)
239
- if State === opts
240
- state, opts = opts, nil
241
- else
242
- state = FAST_STATE_PROTOTYPE.dup
243
- end
244
- if opts
245
- if opts.respond_to? :to_hash
246
- opts = opts.to_hash
247
- elsif opts.respond_to? :to_h
248
- opts = opts.to_h
249
- else
250
- raise TypeError, "can't convert #{opts.class} into Hash"
251
- end
252
- state.configure(opts)
253
- end
254
- state.generate(obj)
255
- end
256
-
257
- # :stopdoc:
258
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
259
- alias fast_unparse fast_generate
260
- module_function :fast_unparse
261
- # :startdoc:
262
-
263
- # Generate a JSON document from the Ruby data structure _obj_ and return it.
264
- # The returned document is a prettier form of the document returned by
265
- # #unparse.
266
- #
267
- # The _opts_ argument can be used to configure the generator. See the
268
- # generate method for a more detailed explanation.
269
- def pretty_generate(obj, opts = nil)
270
- if State === opts
271
- state, opts = opts, nil
272
- else
273
- state = PRETTY_STATE_PROTOTYPE.dup
274
- end
275
- if opts
276
- if opts.respond_to? :to_hash
277
- opts = opts.to_hash
278
- elsif opts.respond_to? :to_h
279
- opts = opts.to_h
280
- else
281
- raise TypeError, "can't convert #{opts.class} into Hash"
282
- end
283
- state.configure(opts)
284
- end
285
- state.generate(obj)
286
- end
287
-
288
- # :stopdoc:
289
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
290
- alias pretty_unparse pretty_generate
291
- module_function :pretty_unparse
292
- # :startdoc:
293
-
294
- class << self
295
- # The global default options for the JSON.load method:
296
- # :max_nesting: false
297
- # :allow_nan: true
298
- # :quirks_mode: true
299
- attr_accessor :load_default_options
300
- end
301
- self.load_default_options = {
302
- :max_nesting => false,
303
- :allow_nan => true,
304
- :quirks_mode => true,
305
- :create_additions => true,
306
- }
307
-
308
- # Load a ruby data structure from a JSON _source_ and return it. A source can
309
- # either be a string-like object, an IO-like object, or an object responding
310
- # to the read method. If _proc_ was given, it will be called with any nested
311
- # Ruby object as an argument recursively in depth first order. To modify the
312
- # default options pass in the optional _options_ argument as well.
313
- #
314
- # BEWARE: This method is meant to serialise data from trusted user input,
315
- # like from your own database server or clients under your control, it could
316
- # be dangerous to allow untrusted users to pass JSON sources into it. The
317
- # default options for the parser can be changed via the load_default_options
318
- # method.
319
- #
320
- # This method is part of the implementation of the load/dump interface of
321
- # Marshal and YAML.
322
- def load(source, proc = nil, options = {})
323
- opts = load_default_options.merge options
324
- if source.respond_to? :to_str
325
- source = source.to_str
326
- elsif source.respond_to? :to_io
327
- source = source.to_io.read
328
- elsif source.respond_to?(:read)
329
- source = source.read
330
- end
331
- if opts[:quirks_mode] && (source.nil? || source.empty?)
332
- source = 'null'
333
- end
334
- result = parse(source, opts)
335
- recurse_proc(result, &proc) if proc
336
- result
337
- end
338
-
339
- # Recursively calls passed _Proc_ if the parsed data structure is an _Array_ or _Hash_
340
- def recurse_proc(result, &proc)
341
- case result
342
- when Array
343
- result.each { |x| recurse_proc x, &proc }
344
- proc.call result
345
- when Hash
346
- result.each { |x, y| recurse_proc x, &proc; recurse_proc y, &proc }
347
- proc.call result
348
- else
349
- proc.call result
350
- end
351
- end
352
-
353
- alias restore load
354
- module_function :restore
355
-
356
- class << self
357
- # The global default options for the JSON.dump method:
358
- # :max_nesting: false
359
- # :allow_nan: true
360
- # :quirks_mode: true
361
- attr_accessor :dump_default_options
362
- end
363
- self.dump_default_options = {
364
- :max_nesting => false,
365
- :allow_nan => true,
366
- :quirks_mode => true,
367
- }
368
-
369
- # Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
370
- # the result.
371
- #
372
- # If anIO (an IO-like object or an object that responds to the write method)
373
- # was given, the resulting JSON is written to it.
374
- #
375
- # If the number of nested arrays or objects exceeds _limit_, an ArgumentError
376
- # exception is raised. This argument is similar (but not exactly the
377
- # same!) to the _limit_ argument in Marshal.dump.
378
- #
379
- # The default options for the generator can be changed via the
380
- # dump_default_options method.
381
- #
382
- # This method is part of the implementation of the load/dump interface of
383
- # Marshal and YAML.
384
- def dump(obj, anIO = nil, limit = nil)
385
- if anIO and limit.nil?
386
- anIO = anIO.to_io if anIO.respond_to?(:to_io)
387
- unless anIO.respond_to?(:write)
388
- limit = anIO
389
- anIO = nil
390
- end
391
- end
392
- opts = JSON.dump_default_options
393
- limit and opts.update(:max_nesting => limit)
394
- result = generate(obj, opts)
395
- if anIO
396
- anIO.write result
397
- anIO
398
- else
399
- result
400
- end
401
- rescue JSON::NestingError
402
- raise ArgumentError, "exceed depth limit"
403
- end
404
-
405
- # Swap consecutive bytes of _string_ in place.
406
- def self.swap!(string) # :nodoc:
407
- 0.upto(string.size / 2) do |i|
408
- break unless string[2 * i + 1]
409
- string[2 * i], string[2 * i + 1] = string[2 * i + 1], string[2 * i]
410
- end
411
- string
412
- end
413
-
414
- # Shortuct for iconv.
415
- if ::String.method_defined?(:encode) &&
416
- # XXX Rubinius doesn't support ruby 1.9 encoding yet
417
- defined?(RUBY_ENGINE) && RUBY_ENGINE != 'rbx'
418
- then
419
- # Encodes string using Ruby's _String.encode_
420
- def self.iconv(to, from, string)
421
- string.encode(to, from)
422
- end
423
- else
424
- require 'iconv'
425
- # Encodes string using _iconv_ library
426
- def self.iconv(to, from, string)
427
- Iconv.conv(to, from, string)
428
- end
429
- end
430
-
431
- if ::Object.method(:const_defined?).arity == 1
432
- def self.const_defined_in?(modul, constant)
433
- modul.const_defined?(constant)
434
- end
435
- else
436
- def self.const_defined_in?(modul, constant)
437
- modul.const_defined?(constant, false)
438
- end
439
- end
440
- end
441
-
442
- module ::Kernel
443
- private
444
-
445
- # Outputs _objs_ to STDOUT as JSON strings in the shortest form, that is in
446
- # one line.
447
- def j(*objs)
448
- objs.each do |obj|
449
- puts JSON::generate(obj, :allow_nan => true, :max_nesting => false)
450
- end
451
- nil
452
- end
453
-
454
- # Ouputs _objs_ to STDOUT as JSON strings in a pretty format, with
455
- # indentation and over many lines.
456
- def jj(*objs)
457
- objs.each do |obj|
458
- puts JSON::pretty_generate(obj, :allow_nan => true, :max_nesting => false)
459
- end
460
- nil
461
- end
462
-
463
- # If _object_ is string-like, parse the string and return the parsed result as
464
- # a Ruby data structure. Otherwise, generate a JSON text from the Ruby data
465
- # structure object and return it.
466
- #
467
- # The _opts_ argument is passed through to generate/parse respectively. See
468
- # generate and parse for their documentation.
469
- def JSON(object, *args)
470
- if object.respond_to? :to_str
471
- JSON.parse(object.to_str, args.first)
472
- else
473
- JSON.generate(object, args.first)
474
- end
475
- end
476
- end
477
-
478
- # Extends any Class to include _json_creatable?_ method.
479
- class ::Class
480
- # Returns true if this class can be used to create an instance
481
- # from a serialised JSON string. The class has to implement a class
482
- # method _json_create_ that expects a hash as first parameter. The hash
483
- # should include the required data.
484
- def json_creatable?
485
- respond_to?(:json_create)
486
- end
487
- end