benschwarz-smoke 0.5.7 → 0.5.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -0
- data/VERSION.yml +1 -1
- metadata +65 -196
- data/Gemfile +0 -10
- data/bin/edit_json.rb +0 -3
- data/bin/restclient +0 -3
- data/vendor/gems/cache/crack-0.1.1.gem +0 -0
- data/vendor/gems/cache/fakeweb-1.2.5.gem +0 -0
- data/vendor/gems/cache/json-1.1.3.gem +0 -0
- data/vendor/gems/cache/rest-client-1.0.1.gem +0 -0
- data/vendor/gems/cache/simple-rss-1.2.gem +0 -0
- data/vendor/gems/cache/wycats-moneta-0.6.0.gem +0 -0
- data/vendor/gems/environment.rb +0 -83
- data/vendor/gems/gems/crack-0.1.1/LICENSE +0 -20
- data/vendor/gems/gems/crack-0.1.1/README.rdoc +0 -22
- data/vendor/gems/gems/crack-0.1.1/VERSION.yml +0 -4
- data/vendor/gems/gems/crack-0.1.1/lib/crack.rb +0 -7
- data/vendor/gems/gems/crack-0.1.1/lib/crack/core_extensions.rb +0 -126
- data/vendor/gems/gems/crack-0.1.1/lib/crack/json.rb +0 -66
- data/vendor/gems/gems/crack-0.1.1/lib/crack/xml.rb +0 -211
- data/vendor/gems/gems/crack-0.1.1/test/crack_test.rb +0 -4
- data/vendor/gems/gems/crack-0.1.1/test/json_test.rb +0 -42
- data/vendor/gems/gems/crack-0.1.1/test/test_helper.rb +0 -12
- data/vendor/gems/gems/crack-0.1.1/test/xml_test.rb +0 -451
- data/vendor/gems/gems/fakeweb-1.2.5/CHANGELOG +0 -163
- data/vendor/gems/gems/fakeweb-1.2.5/LICENSE.txt +0 -281
- data/vendor/gems/gems/fakeweb-1.2.5/README.rdoc +0 -193
- data/vendor/gems/gems/fakeweb-1.2.5/Rakefile +0 -76
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web.rb +0 -172
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/ext/net_http.rb +0 -71
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/registry.rb +0 -103
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/responder.rb +0 -113
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/response.rb +0 -10
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/stub_socket.rb +0 -15
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fake_web/utility.rb +0 -22
- data/vendor/gems/gems/fakeweb-1.2.5/lib/fakeweb.rb +0 -2
- data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_from_curl +0 -12
- data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_with_transfer_encoding +0 -17
- data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/google_response_without_transfer_encoding +0 -11
- data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/test_example.txt +0 -1
- data/vendor/gems/gems/fakeweb-1.2.5/test/fixtures/test_txt_file +0 -3
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_allow_net_connect.rb +0 -85
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_deprecations.rb +0 -54
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_authentication.rb +0 -92
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_web.rb +0 -518
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_fake_web_open_uri.rb +0 -58
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_helper.rb +0 -74
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_missing_open_uri.rb +0 -25
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_precedence.rb +0 -51
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_query_string.rb +0 -45
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_regexes.rb +0 -103
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_response_headers.rb +0 -67
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_trailing_slashes.rb +0 -53
- data/vendor/gems/gems/fakeweb-1.2.5/test/test_utility.rb +0 -70
- data/vendor/gems/gems/json-1.1.3/CHANGES +0 -93
- data/vendor/gems/gems/json-1.1.3/GPL +0 -340
- data/vendor/gems/gems/json-1.1.3/README +0 -78
- data/vendor/gems/gems/json-1.1.3/RUBY +0 -58
- data/vendor/gems/gems/json-1.1.3/Rakefile +0 -309
- data/vendor/gems/gems/json-1.1.3/TODO +0 -1
- data/vendor/gems/gems/json-1.1.3/VERSION +0 -1
- data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark.txt +0 -133
- data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_generator.rb +0 -48
- data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_parser.rb +0 -26
- data/vendor/gems/gems/json-1.1.3/benchmarks/benchmark_rails.rb +0 -26
- data/vendor/gems/gems/json-1.1.3/bin/edit_json.rb +0 -10
- data/vendor/gems/gems/json-1.1.3/bin/prettify_json.rb +0 -76
- data/vendor/gems/gems/json-1.1.3/data/example.json +0 -1
- data/vendor/gems/gems/json-1.1.3/data/index.html +0 -38
- data/vendor/gems/gems/json-1.1.3/data/prototype.js +0 -4184
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator.bundle +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/Makefile +0 -150
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/extconf.rb +0 -9
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.bundle +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.c +0 -875
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/generator.o +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.c +0 -182
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.h +0 -53
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/generator/unicode.o +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser.bundle +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/Makefile +0 -150
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/extconf.rb +0 -9
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.bundle +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.c +0 -1758
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.o +0 -0
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/parser.rl +0 -638
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.c +0 -154
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.h +0 -58
- data/vendor/gems/gems/json-1.1.3/ext/json/ext/parser/unicode.o +0 -0
- data/vendor/gems/gems/json-1.1.3/install.rb +0 -26
- data/vendor/gems/gems/json-1.1.3/lib/json.rb +0 -235
- data/vendor/gems/gems/json-1.1.3/lib/json/Array.xpm +0 -21
- data/vendor/gems/gems/json-1.1.3/lib/json/FalseClass.xpm +0 -21
- data/vendor/gems/gems/json-1.1.3/lib/json/Hash.xpm +0 -21
- data/vendor/gems/gems/json-1.1.3/lib/json/Key.xpm +0 -73
- data/vendor/gems/gems/json-1.1.3/lib/json/NilClass.xpm +0 -21
- data/vendor/gems/gems/json-1.1.3/lib/json/Numeric.xpm +0 -28
- data/vendor/gems/gems/json-1.1.3/lib/json/String.xpm +0 -96
- data/vendor/gems/gems/json-1.1.3/lib/json/TrueClass.xpm +0 -21
- data/vendor/gems/gems/json-1.1.3/lib/json/add/core.rb +0 -135
- data/vendor/gems/gems/json-1.1.3/lib/json/add/rails.rb +0 -58
- data/vendor/gems/gems/json-1.1.3/lib/json/common.rb +0 -354
- data/vendor/gems/gems/json-1.1.3/lib/json/editor.rb +0 -1362
- data/vendor/gems/gems/json-1.1.3/lib/json/ext.rb +0 -13
- data/vendor/gems/gems/json-1.1.3/lib/json/json.xpm +0 -1499
- data/vendor/gems/gems/json-1.1.3/lib/json/pure.rb +0 -75
- data/vendor/gems/gems/json-1.1.3/lib/json/pure/generator.rb +0 -394
- data/vendor/gems/gems/json-1.1.3/lib/json/pure/parser.rb +0 -259
- data/vendor/gems/gems/json-1.1.3/lib/json/version.rb +0 -9
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail1.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail10.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail11.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail12.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail13.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail14.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail18.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail19.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail2.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail20.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail21.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail22.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail23.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail24.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail25.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail27.json +0 -2
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail28.json +0 -2
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail3.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail4.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail5.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail6.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail7.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail8.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/fail9.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass1.json +0 -56
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass15.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass16.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass17.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass2.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass26.json +0 -1
- data/vendor/gems/gems/json-1.1.3/tests/fixtures/pass3.json +0 -6
- data/vendor/gems/gems/json-1.1.3/tests/runner.rb +0 -25
- data/vendor/gems/gems/json-1.1.3/tests/test_json.rb +0 -293
- data/vendor/gems/gems/json-1.1.3/tests/test_json_addition.rb +0 -161
- data/vendor/gems/gems/json-1.1.3/tests/test_json_fixtures.rb +0 -30
- data/vendor/gems/gems/json-1.1.3/tests/test_json_generate.rb +0 -100
- data/vendor/gems/gems/json-1.1.3/tests/test_json_rails.rb +0 -118
- data/vendor/gems/gems/json-1.1.3/tests/test_json_unicode.rb +0 -61
- data/vendor/gems/gems/json-1.1.3/tools/fuzz.rb +0 -140
- data/vendor/gems/gems/json-1.1.3/tools/server.rb +0 -62
- data/vendor/gems/gems/rest-client-1.0.1/README.rdoc +0 -151
- data/vendor/gems/gems/rest-client-1.0.1/Rakefile +0 -85
- data/vendor/gems/gems/rest-client-1.0.1/bin/restclient +0 -87
- data/vendor/gems/gems/rest-client-1.0.1/lib/rest_client.rb +0 -2
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient.rb +0 -93
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/exceptions.rb +0 -84
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/mixin/response.rb +0 -43
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/raw_response.rb +0 -30
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/request.rb +0 -236
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/resource.rb +0 -146
- data/vendor/gems/gems/rest-client-1.0.1/lib/restclient/response.rb +0 -20
- data/vendor/gems/gems/rest-client-1.0.1/spec/base.rb +0 -4
- data/vendor/gems/gems/rest-client-1.0.1/spec/exceptions_spec.rb +0 -54
- data/vendor/gems/gems/rest-client-1.0.1/spec/mixin/response_spec.rb +0 -46
- data/vendor/gems/gems/rest-client-1.0.1/spec/raw_response_spec.rb +0 -17
- data/vendor/gems/gems/rest-client-1.0.1/spec/request_spec.rb +0 -462
- data/vendor/gems/gems/rest-client-1.0.1/spec/resource_spec.rb +0 -75
- data/vendor/gems/gems/rest-client-1.0.1/spec/response_spec.rb +0 -16
- data/vendor/gems/gems/rest-client-1.0.1/spec/restclient_spec.rb +0 -53
- data/vendor/gems/gems/simple-rss-1.2/LICENSE +0 -429
- data/vendor/gems/gems/simple-rss-1.2/README +0 -43
- data/vendor/gems/gems/simple-rss-1.2/Rakefile +0 -212
- data/vendor/gems/gems/simple-rss-1.2/lib/simple-rss.rb +0 -149
- data/vendor/gems/gems/simple-rss-1.2/test/base/base_test.rb +0 -51
- data/vendor/gems/gems/simple-rss-1.2/test/data/atom.xml +0 -45
- data/vendor/gems/gems/simple-rss-1.2/test/data/not-rss.xml +0 -8
- data/vendor/gems/gems/simple-rss-1.2/test/data/rss09.rdf +0 -79
- data/vendor/gems/gems/simple-rss-1.2/test/data/rss20.xml +0 -818
- data/vendor/gems/gems/simple-rss-1.2/test/test_helper.rb +0 -4
- data/vendor/gems/gems/wycats-moneta-0.6.0/LICENSE +0 -20
- data/vendor/gems/gems/wycats-moneta-0.6.0/README +0 -50
- data/vendor/gems/gems/wycats-moneta-0.6.0/Rakefile +0 -60
- data/vendor/gems/gems/wycats-moneta-0.6.0/TODO +0 -4
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta.rb +0 -76
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/datamapper.rb +0 -117
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/file.rb +0 -91
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/memcache.rb +0 -52
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/memory.rb +0 -11
- data/vendor/gems/gems/wycats-moneta-0.6.0/lib/moneta/xattr.rb +0 -58
- data/vendor/gems/specifications/crack-0.1.1.gemspec +0 -29
- data/vendor/gems/specifications/fakeweb-1.2.5.gemspec +0 -34
- data/vendor/gems/specifications/json-1.1.3.gemspec +0 -33
- data/vendor/gems/specifications/rest-client-1.0.1.gemspec +0 -30
- data/vendor/gems/specifications/simple-rss-1.2.gemspec +0 -27
- data/vendor/gems/specifications/wycats-moneta-0.6.0.gemspec +0 -29
@@ -1,22 +0,0 @@
|
|
1
|
-
= crack
|
2
|
-
|
3
|
-
Really simple JSON and XML parsing, ripped from Merb and Rails. The XML parser is ripped from Merb and the JSON parser is ripped from Rails. I take no credit, just packaged them for all to enjoy and easily use.
|
4
|
-
|
5
|
-
= usage
|
6
|
-
|
7
|
-
gem 'crack'
|
8
|
-
require 'crack' # for xml and json
|
9
|
-
require 'crack/json' # for just json
|
10
|
-
require 'crack/xml' # for just xml
|
11
|
-
|
12
|
-
= examples
|
13
|
-
|
14
|
-
Crack::XML.parse("<tag>This is the contents</tag>")
|
15
|
-
# => {'tag' => 'This is the contents'}
|
16
|
-
|
17
|
-
Crack::JSON.parse('{"tag":"This is the contents"}')
|
18
|
-
# => {'tag' => 'This is the contents'}
|
19
|
-
|
20
|
-
== Copyright
|
21
|
-
|
22
|
-
Copyright (c) 2009 John Nunemaker. See LICENSE for details.
|
@@ -1,126 +0,0 @@
|
|
1
|
-
class Object #:nodoc:
|
2
|
-
# @return <TrueClass, FalseClass>
|
3
|
-
#
|
4
|
-
# @example [].blank? #=> true
|
5
|
-
# @example [1].blank? #=> false
|
6
|
-
# @example [nil].blank? #=> false
|
7
|
-
#
|
8
|
-
# Returns true if the object is nil or empty (if applicable)
|
9
|
-
def blank?
|
10
|
-
nil? || (respond_to?(:empty?) && empty?)
|
11
|
-
end unless method_defined?(:blank?)
|
12
|
-
end # class Object
|
13
|
-
|
14
|
-
class Numeric #:nodoc:
|
15
|
-
# @return <TrueClass, FalseClass>
|
16
|
-
#
|
17
|
-
# Numerics can't be blank
|
18
|
-
def blank?
|
19
|
-
false
|
20
|
-
end unless method_defined?(:blank?)
|
21
|
-
end # class Numeric
|
22
|
-
|
23
|
-
class NilClass #:nodoc:
|
24
|
-
# @return <TrueClass, FalseClass>
|
25
|
-
#
|
26
|
-
# Nils are always blank
|
27
|
-
def blank?
|
28
|
-
true
|
29
|
-
end unless method_defined?(:blank?)
|
30
|
-
end # class NilClass
|
31
|
-
|
32
|
-
class TrueClass #:nodoc:
|
33
|
-
# @return <TrueClass, FalseClass>
|
34
|
-
#
|
35
|
-
# True is not blank.
|
36
|
-
def blank?
|
37
|
-
false
|
38
|
-
end unless method_defined?(:blank?)
|
39
|
-
end # class TrueClass
|
40
|
-
|
41
|
-
class FalseClass #:nodoc:
|
42
|
-
# False is always blank.
|
43
|
-
def blank?
|
44
|
-
true
|
45
|
-
end unless method_defined?(:blank?)
|
46
|
-
end # class FalseClass
|
47
|
-
|
48
|
-
class String #:nodoc:
|
49
|
-
# @example "".blank? #=> true
|
50
|
-
# @example " ".blank? #=> true
|
51
|
-
# @example " hey ho ".blank? #=> false
|
52
|
-
#
|
53
|
-
# @return <TrueClass, FalseClass>
|
54
|
-
#
|
55
|
-
# Strips out whitespace then tests if the string is empty.
|
56
|
-
def blank?
|
57
|
-
strip.empty?
|
58
|
-
end unless method_defined?(:blank?)
|
59
|
-
|
60
|
-
def snake_case
|
61
|
-
return self.downcase if self =~ /^[A-Z]+$/
|
62
|
-
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
|
63
|
-
return $+.downcase
|
64
|
-
end unless method_defined?(:snake_case)
|
65
|
-
end # class String
|
66
|
-
|
67
|
-
class Hash #:nodoc:
|
68
|
-
# @return <String> This hash as a query string
|
69
|
-
#
|
70
|
-
# @example
|
71
|
-
# { :name => "Bob",
|
72
|
-
# :address => {
|
73
|
-
# :street => '111 Ruby Ave.',
|
74
|
-
# :city => 'Ruby Central',
|
75
|
-
# :phones => ['111-111-1111', '222-222-2222']
|
76
|
-
# }
|
77
|
-
# }.to_params
|
78
|
-
# #=> "name=Bob&address[city]=Ruby Central&address[phones][]=111-111-1111&address[phones][]=222-222-2222&address[street]=111 Ruby Ave."
|
79
|
-
def to_params
|
80
|
-
params = self.map { |k,v| normalize_param(k,v) }.join
|
81
|
-
params.chop! # trailing &
|
82
|
-
params
|
83
|
-
end
|
84
|
-
|
85
|
-
# @param key<Object> The key for the param.
|
86
|
-
# @param value<Object> The value for the param.
|
87
|
-
#
|
88
|
-
# @return <String> This key value pair as a param
|
89
|
-
#
|
90
|
-
# @example normalize_param(:name, "Bob Jones") #=> "name=Bob%20Jones&"
|
91
|
-
def normalize_param(key, value)
|
92
|
-
param = ''
|
93
|
-
stack = []
|
94
|
-
|
95
|
-
if value.is_a?(Array)
|
96
|
-
param << value.map { |element| normalize_param("#{key}[]", element) }.join
|
97
|
-
elsif value.is_a?(Hash)
|
98
|
-
stack << [key,value]
|
99
|
-
else
|
100
|
-
param << "#{key}=#{URI.encode(value.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}&"
|
101
|
-
end
|
102
|
-
|
103
|
-
stack.each do |parent, hash|
|
104
|
-
hash.each do |key, value|
|
105
|
-
if value.is_a?(Hash)
|
106
|
-
stack << ["#{parent}[#{key}]", value]
|
107
|
-
else
|
108
|
-
param << normalize_param("#{parent}[#{key}]", value)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
param
|
114
|
-
end
|
115
|
-
|
116
|
-
# @return <String> The hash as attributes for an XML tag.
|
117
|
-
#
|
118
|
-
# @example
|
119
|
-
# { :one => 1, "two"=>"TWO" }.to_xml_attributes
|
120
|
-
# #=> 'one="1" two="TWO"'
|
121
|
-
def to_xml_attributes
|
122
|
-
map do |k,v|
|
123
|
-
%{#{k.to_s.snake_case.sub(/^(.{1,1})/) { |m| m.downcase }}="#{v}"}
|
124
|
-
end.join(' ')
|
125
|
-
end
|
126
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# Copyright (c) 2004-2008 David Heinemeier Hansson
|
2
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
3
|
-
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
4
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
5
|
-
|
6
|
-
require 'yaml'
|
7
|
-
require 'strscan'
|
8
|
-
|
9
|
-
module Crack
|
10
|
-
class JSON
|
11
|
-
def self.parse(json)
|
12
|
-
YAML.load(unescape(convert_json_to_yaml(json)))
|
13
|
-
rescue ArgumentError => e
|
14
|
-
raise ParseError, "Invalid JSON string"
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
def self.unescape(str)
|
19
|
-
str.gsub(/\\u([0-9a-f]{4})/) { [$1.hex].pack("U") }
|
20
|
-
end
|
21
|
-
|
22
|
-
# matches YAML-formatted dates
|
23
|
-
DATE_REGEX = /^\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[ \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?$/
|
24
|
-
|
25
|
-
# Ensure that ":" and "," are always followed by a space
|
26
|
-
def self.convert_json_to_yaml(json) #:nodoc:
|
27
|
-
scanner, quoting, marks, pos, times = StringScanner.new(json), false, [], nil, []
|
28
|
-
while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
|
29
|
-
case char = scanner[1]
|
30
|
-
when '"', "'"
|
31
|
-
if !quoting
|
32
|
-
quoting = char
|
33
|
-
pos = scanner.pos
|
34
|
-
elsif quoting == char
|
35
|
-
if json[pos..scanner.pos-2] =~ DATE_REGEX
|
36
|
-
# found a date, track the exact positions of the quotes so we can remove them later.
|
37
|
-
# oh, and increment them for each current mark, each one is an extra padded space that bumps
|
38
|
-
# the position in the final YAML output
|
39
|
-
total_marks = marks.size
|
40
|
-
times << pos+total_marks << scanner.pos+total_marks
|
41
|
-
end
|
42
|
-
quoting = false
|
43
|
-
end
|
44
|
-
when ":",","
|
45
|
-
marks << scanner.pos - 1 unless quoting
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
if marks.empty?
|
50
|
-
json.gsub(/\\\//, '/')
|
51
|
-
else
|
52
|
-
left_pos = [-1].push(*marks)
|
53
|
-
right_pos = marks << json.length
|
54
|
-
output = []
|
55
|
-
left_pos.each_with_index do |left, i|
|
56
|
-
output << json[left.succ..right_pos[i]]
|
57
|
-
end
|
58
|
-
output = output * " "
|
59
|
-
|
60
|
-
times.each { |i| output[i-1] = ' ' }
|
61
|
-
output.gsub!(/\\\//, '/')
|
62
|
-
output
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,211 +0,0 @@
|
|
1
|
-
require 'rexml/parsers/streamparser'
|
2
|
-
require 'rexml/parsers/baseparser'
|
3
|
-
require 'rexml/light/node'
|
4
|
-
require 'date'
|
5
|
-
require 'time'
|
6
|
-
require 'yaml'
|
7
|
-
require 'bigdecimal'
|
8
|
-
|
9
|
-
# This is a slighly modified version of the XMLUtilityNode from
|
10
|
-
# http://merb.devjavu.com/projects/merb/ticket/95 (has.sox@gmail.com)
|
11
|
-
# It's mainly just adding vowels, as I ht cd wth n vwls :)
|
12
|
-
# This represents the hard part of the work, all I did was change the
|
13
|
-
# underlying parser.
|
14
|
-
class REXMLUtilityNode #:nodoc:
|
15
|
-
attr_accessor :name, :attributes, :children, :type
|
16
|
-
|
17
|
-
def self.typecasts
|
18
|
-
@@typecasts
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.typecasts=(obj)
|
22
|
-
@@typecasts = obj
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.available_typecasts
|
26
|
-
@@available_typecasts
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.available_typecasts=(obj)
|
30
|
-
@@available_typecasts = obj
|
31
|
-
end
|
32
|
-
|
33
|
-
self.typecasts = {}
|
34
|
-
self.typecasts["integer"] = lambda{|v| v.nil? ? nil : v.to_i}
|
35
|
-
self.typecasts["boolean"] = lambda{|v| v.nil? ? nil : (v.strip != "false")}
|
36
|
-
self.typecasts["datetime"] = lambda{|v| v.nil? ? nil : Time.parse(v).utc}
|
37
|
-
self.typecasts["date"] = lambda{|v| v.nil? ? nil : Date.parse(v)}
|
38
|
-
self.typecasts["dateTime"] = lambda{|v| v.nil? ? nil : Time.parse(v).utc}
|
39
|
-
self.typecasts["decimal"] = lambda{|v| v.nil? ? nil : BigDecimal(v.to_s)}
|
40
|
-
self.typecasts["double"] = lambda{|v| v.nil? ? nil : v.to_f}
|
41
|
-
self.typecasts["float"] = lambda{|v| v.nil? ? nil : v.to_f}
|
42
|
-
self.typecasts["symbol"] = lambda{|v| v.nil? ? nil : v.to_sym}
|
43
|
-
self.typecasts["string"] = lambda{|v| v.to_s}
|
44
|
-
self.typecasts["yaml"] = lambda{|v| v.nil? ? nil : YAML.load(v)}
|
45
|
-
self.typecasts["base64Binary"] = lambda{|v| v.unpack('m').first }
|
46
|
-
|
47
|
-
self.available_typecasts = self.typecasts.keys
|
48
|
-
|
49
|
-
def initialize(name, attributes = {})
|
50
|
-
@name = name.tr("-", "_")
|
51
|
-
# leave the type alone if we don't know what it is
|
52
|
-
@type = self.class.available_typecasts.include?(attributes["type"]) ? attributes.delete("type") : attributes["type"]
|
53
|
-
|
54
|
-
@nil_element = attributes.delete("nil") == "true"
|
55
|
-
@attributes = undasherize_keys(attributes)
|
56
|
-
@children = []
|
57
|
-
@text = false
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_node(node)
|
61
|
-
@text = true if node.is_a? String
|
62
|
-
@children << node
|
63
|
-
end
|
64
|
-
|
65
|
-
def to_hash
|
66
|
-
if @type == "file"
|
67
|
-
f = StringIO.new((@children.first || '').unpack('m').first)
|
68
|
-
class << f
|
69
|
-
attr_accessor :original_filename, :content_type
|
70
|
-
end
|
71
|
-
f.original_filename = attributes['name'] || 'untitled'
|
72
|
-
f.content_type = attributes['content_type'] || 'application/octet-stream'
|
73
|
-
return {name => f}
|
74
|
-
end
|
75
|
-
|
76
|
-
if @text
|
77
|
-
return { name => typecast_value( translate_xml_entities( inner_html ) ) }
|
78
|
-
else
|
79
|
-
#change repeating groups into an array
|
80
|
-
groups = @children.inject({}) { |s,e| (s[e.name] ||= []) << e; s }
|
81
|
-
|
82
|
-
out = nil
|
83
|
-
if @type == "array"
|
84
|
-
out = []
|
85
|
-
groups.each do |k, v|
|
86
|
-
if v.size == 1
|
87
|
-
out << v.first.to_hash.entries.first.last
|
88
|
-
else
|
89
|
-
out << v.map{|e| e.to_hash[k]}
|
90
|
-
end
|
91
|
-
end
|
92
|
-
out = out.flatten
|
93
|
-
|
94
|
-
else # If Hash
|
95
|
-
out = {}
|
96
|
-
groups.each do |k,v|
|
97
|
-
if v.size == 1
|
98
|
-
out.merge!(v.first)
|
99
|
-
else
|
100
|
-
out.merge!( k => v.map{|e| e.to_hash[k]})
|
101
|
-
end
|
102
|
-
end
|
103
|
-
out.merge! attributes unless attributes.empty?
|
104
|
-
out = out.empty? ? nil : out
|
105
|
-
end
|
106
|
-
|
107
|
-
if @type && out.nil?
|
108
|
-
{ name => typecast_value(out) }
|
109
|
-
else
|
110
|
-
{ name => out }
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
# Typecasts a value based upon its type. For instance, if
|
116
|
-
# +node+ has #type == "integer",
|
117
|
-
# {{[node.typecast_value("12") #=> 12]}}
|
118
|
-
#
|
119
|
-
# @param value<String> The value that is being typecast.
|
120
|
-
#
|
121
|
-
# @details [:type options]
|
122
|
-
# "integer"::
|
123
|
-
# converts +value+ to an integer with #to_i
|
124
|
-
# "boolean"::
|
125
|
-
# checks whether +value+, after removing spaces, is the literal
|
126
|
-
# "true"
|
127
|
-
# "datetime"::
|
128
|
-
# Parses +value+ using Time.parse, and returns a UTC Time
|
129
|
-
# "date"::
|
130
|
-
# Parses +value+ using Date.parse
|
131
|
-
#
|
132
|
-
# @return <Integer, TrueClass, FalseClass, Time, Date, Object>
|
133
|
-
# The result of typecasting +value+.
|
134
|
-
#
|
135
|
-
# @note
|
136
|
-
# If +self+ does not have a "type" key, or if it's not one of the
|
137
|
-
# options specified above, the raw +value+ will be returned.
|
138
|
-
def typecast_value(value)
|
139
|
-
return value unless @type
|
140
|
-
proc = self.class.typecasts[@type]
|
141
|
-
proc.nil? ? value : proc.call(value)
|
142
|
-
end
|
143
|
-
|
144
|
-
# Convert basic XML entities into their literal values.
|
145
|
-
#
|
146
|
-
# @param value<#gsub> An XML fragment.
|
147
|
-
#
|
148
|
-
# @return <#gsub> The XML fragment after converting entities.
|
149
|
-
def translate_xml_entities(value)
|
150
|
-
value.gsub(/</, "<").
|
151
|
-
gsub(/>/, ">").
|
152
|
-
gsub(/"/, '"').
|
153
|
-
gsub(/'/, "'").
|
154
|
-
gsub(/&/, "&")
|
155
|
-
end
|
156
|
-
|
157
|
-
# Take keys of the form foo-bar and convert them to foo_bar
|
158
|
-
def undasherize_keys(params)
|
159
|
-
params.keys.each do |key, value|
|
160
|
-
params[key.tr("-", "_")] = params.delete(key)
|
161
|
-
end
|
162
|
-
params
|
163
|
-
end
|
164
|
-
|
165
|
-
# Get the inner_html of the REXML node.
|
166
|
-
def inner_html
|
167
|
-
@children.join
|
168
|
-
end
|
169
|
-
|
170
|
-
# Converts the node into a readable HTML node.
|
171
|
-
#
|
172
|
-
# @return <String> The HTML node in text form.
|
173
|
-
def to_html
|
174
|
-
attributes.merge!(:type => @type ) if @type
|
175
|
-
"<#{name}#{attributes.to_xml_attributes}>#{@nil_element ? '' : inner_html}</#{name}>"
|
176
|
-
end
|
177
|
-
|
178
|
-
# @alias #to_html #to_s
|
179
|
-
def to_s
|
180
|
-
to_html
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
module Crack
|
185
|
-
class XML
|
186
|
-
def self.parse(xml)
|
187
|
-
stack = []
|
188
|
-
parser = REXML::Parsers::BaseParser.new(xml)
|
189
|
-
|
190
|
-
while true
|
191
|
-
event = parser.pull
|
192
|
-
case event[0]
|
193
|
-
when :end_document
|
194
|
-
break
|
195
|
-
when :end_doctype, :start_doctype
|
196
|
-
# do nothing
|
197
|
-
when :start_element
|
198
|
-
stack.push REXMLUtilityNode.new(event[1], event[2])
|
199
|
-
when :end_element
|
200
|
-
if stack.size > 1
|
201
|
-
temp = stack.pop
|
202
|
-
stack.last.add_node(temp)
|
203
|
-
end
|
204
|
-
when :text, :cdata
|
205
|
-
stack.last.add_node(event[1]) unless event[1].strip.length == 0 || stack.empty?
|
206
|
-
end
|
207
|
-
end
|
208
|
-
stack.length > 0 ? stack.pop.to_hash : {}
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|