benschwarz-smoke 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +47 -0
- data/VERSION.yml +2 -2
- data/lib/core_ext/string.rb +6 -0
- data/lib/smoke/cache.rb +38 -23
- data/lib/smoke/request.rb +4 -8
- data/lib/smoke.rb +7 -2
- data/rdoc/classes/Smoke/Origin.html +340 -0
- data/rdoc/classes/Smoke/Source/Data.html +126 -0
- data/rdoc/classes/Smoke/Source/Feed.html +117 -0
- data/rdoc/classes/Smoke/Source/YQL.html +223 -0
- data/rdoc/classes/Smoke.html +260 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_markdown.html +180 -0
- data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
- data/rdoc/files/lib/smoke/origin_rb.html +49 -0
- data/rdoc/files/lib/smoke/request_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
- data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
- data/rdoc/files/lib/smoke_rb.html +65 -0
- data/rdoc/fr_class_index.html +21 -0
- data/rdoc/fr_file_index.html +28 -0
- data/rdoc/fr_method_index.html +4459 -0
- data/rdoc/index.html +15 -0
- data/rdoc/rdoc-style.css +319 -0
- data/spec/smoke/cache_spec.rb +28 -6
- data/vendor/crack/History +15 -0
- data/vendor/crack/LICENSE +20 -0
- data/vendor/crack/README.rdoc +42 -0
- data/vendor/crack/Rakefile +49 -0
- data/vendor/crack/VERSION.yml +4 -0
- data/vendor/crack/crack.gemspec +61 -0
- data/vendor/crack/lib/crack/core_extensions.rb +128 -0
- data/vendor/crack/lib/crack/json.rb +68 -0
- data/vendor/crack/lib/crack/xml.rb +214 -0
- data/vendor/crack/lib/crack.rb +7 -0
- data/vendor/crack/test/crack_test.rb +4 -0
- data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
- data/vendor/crack/test/data/twittersearch-ie.json +1 -0
- data/vendor/crack/test/hash_test.rb +56 -0
- data/vendor/crack/test/json_test.rb +66 -0
- data/vendor/crack/test/string_test.rb +31 -0
- data/vendor/crack/test/test_helper.rb +12 -0
- data/vendor/crack/test/xml_test.rb +489 -0
- data/vendor/dependencies/README.markdown +113 -0
- data/vendor/dependencies/Rakefile +5 -0
- data/vendor/dependencies/bin/dep +83 -0
- data/vendor/dependencies/dependencies.gemspec +15 -0
- data/vendor/dependencies/dependencies.gemspec.erb +27 -0
- data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
- data/vendor/dependencies/lib/dependencies.rb +5 -0
- data/vendor/dependencies/test/dependencies_test.rb +228 -0
- data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
- data/vendor/fakeweb/CHANGELOG +163 -0
- data/vendor/fakeweb/LICENSE.txt +281 -0
- data/vendor/fakeweb/README.rdoc +193 -0
- data/vendor/fakeweb/Rakefile +76 -0
- data/vendor/fakeweb/fakeweb.gemspec +21 -0
- data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
- data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
- data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
- data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
- data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
- data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
- data/vendor/fakeweb/lib/fake_web.rb +172 -0
- data/vendor/fakeweb/lib/fakeweb.rb +2 -0
- data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
- data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
- data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
- data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
- data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
- data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
- data/vendor/fakeweb/test/test_deprecations.rb +54 -0
- data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
- data/vendor/fakeweb/test/test_fake_web.rb +535 -0
- data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
- data/vendor/fakeweb/test/test_helper.rb +74 -0
- data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
- data/vendor/fakeweb/test/test_precedence.rb +51 -0
- data/vendor/fakeweb/test/test_query_string.rb +45 -0
- data/vendor/fakeweb/test/test_regexes.rb +103 -0
- data/vendor/fakeweb/test/test_response_headers.rb +73 -0
- data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
- data/vendor/fakeweb/test/test_utility.rb +70 -0
- data/vendor/json-1.1.3/CHANGES +93 -0
- data/vendor/json-1.1.3/GPL +340 -0
- data/vendor/json-1.1.3/README +78 -0
- data/vendor/json-1.1.3/RUBY +58 -0
- data/vendor/json-1.1.3/Rakefile +309 -0
- data/vendor/json-1.1.3/TODO +1 -0
- data/vendor/json-1.1.3/VERSION +1 -0
- data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
- data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
- data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
- data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
- data/vendor/json-1.1.3/data/example.json +1 -0
- data/vendor/json-1.1.3/data/index.html +38 -0
- data/vendor/json-1.1.3/data/prototype.js +4184 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
- data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
- data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
- data/vendor/json-1.1.3/install.rb +26 -0
- data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
- data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
- data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
- data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
- data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
- data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
- data/vendor/json-1.1.3/lib/json/common.rb +354 -0
- data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
- data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
- data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
- data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
- data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
- data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
- data/vendor/json-1.1.3/lib/json/version.rb +9 -0
- data/vendor/json-1.1.3/lib/json.rb +235 -0
- data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
- data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
- data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
- data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
- data/vendor/json-1.1.3/tests/runner.rb +25 -0
- data/vendor/json-1.1.3/tests/test_json.rb +293 -0
- data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
- data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
- data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
- data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
- data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
- data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
- data/vendor/json-1.1.3/tools/server.rb +62 -0
- data/vendor/moneta/LICENSE +20 -0
- data/vendor/moneta/README +51 -0
- data/vendor/moneta/Rakefile +60 -0
- data/vendor/moneta/TODO +4 -0
- data/vendor/moneta/benchmarks/various.rb +234 -0
- data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
- data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
- data/vendor/moneta/lib/moneta/couch.rb +63 -0
- data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
- data/vendor/moneta/lib/moneta/file.rb +91 -0
- data/vendor/moneta/lib/moneta/lmc.rb +52 -0
- data/vendor/moneta/lib/moneta/memcache.rb +53 -0
- data/vendor/moneta/lib/moneta/memory.rb +11 -0
- data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
- data/vendor/moneta/lib/moneta/redis.rb +49 -0
- data/vendor/moneta/lib/moneta/rufus.rb +41 -0
- data/vendor/moneta/lib/moneta/s3.rb +162 -0
- data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
- data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
- data/vendor/moneta/lib/moneta/xattr.rb +58 -0
- data/vendor/moneta/lib/moneta.rb +76 -0
- data/vendor/moneta/moneta.gemspec +32 -0
- data/vendor/moneta/script/destroy +14 -0
- data/vendor/moneta/script/generate +14 -0
- data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
- data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
- data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
- data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
- data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
- data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
- data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
- data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
- data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
- data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
- data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
- data/vendor/moneta/spec/shared.rb +122 -0
- data/vendor/moneta/spec/spec_helper.rb +7 -0
- data/vendor/rest-client/README.rdoc +151 -0
- data/vendor/rest-client/Rakefile +58 -0
- data/vendor/rest-client/VERSION +1 -0
- data/vendor/rest-client/bin/restclient +87 -0
- data/vendor/rest-client/lib/rest_client.rb +2 -0
- data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
- data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
- data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
- data/vendor/rest-client/lib/restclient/request.rb +238 -0
- data/vendor/rest-client/lib/restclient/resource.rb +146 -0
- data/vendor/rest-client/lib/restclient/response.rb +20 -0
- data/vendor/rest-client/lib/restclient.rb +99 -0
- data/vendor/rest-client/rest-client.gemspec +66 -0
- data/vendor/rest-client/spec/base.rb +4 -0
- data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
- data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
- data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
- data/vendor/rest-client/spec/request_spec.rb +476 -0
- data/vendor/rest-client/spec/resource_spec.rb +75 -0
- data/vendor/rest-client/spec/response_spec.rb +16 -0
- data/vendor/rest-client/spec/restclient_spec.rb +53 -0
- data/vendor/simple-rss/LICENSE +429 -0
- data/vendor/simple-rss/README +43 -0
- data/vendor/simple-rss/Rakefile +212 -0
- data/vendor/simple-rss/install.rb +40 -0
- data/vendor/simple-rss/lib/simple-rss.rb +150 -0
- data/vendor/simple-rss/simple-rss.gemspec +12 -0
- data/vendor/simple-rss/test/base/base_test.rb +51 -0
- data/vendor/simple-rss/test/data/atom.xml +45 -0
- data/vendor/simple-rss/test/data/not-rss.xml +8 -0
- data/vendor/simple-rss/test/data/rss09.rdf +79 -0
- data/vendor/simple-rss/test/data/rss20.xml +818 -0
- data/vendor/simple-rss/test/test_helper.rb +4 -0
- metadata +314 -40
@@ -0,0 +1,489 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class XmlTest < Test::Unit::TestCase
|
4
|
+
should "should transform a simple tag with content" do
|
5
|
+
xml = "<tag>This is the contents</tag>"
|
6
|
+
Crack::XML.parse(xml).should == { 'tag' => 'This is the contents' }
|
7
|
+
end
|
8
|
+
|
9
|
+
should "should work with cdata tags" do
|
10
|
+
xml = <<-END
|
11
|
+
<tag>
|
12
|
+
<![CDATA[
|
13
|
+
text inside cdata
|
14
|
+
]]>
|
15
|
+
</tag>
|
16
|
+
END
|
17
|
+
Crack::XML.parse(xml)["tag"].strip.should == "text inside cdata"
|
18
|
+
end
|
19
|
+
|
20
|
+
should "should transform a simple tag with attributes" do
|
21
|
+
xml = "<tag attr1='1' attr2='2'></tag>"
|
22
|
+
hash = { 'tag' => { 'attr1' => '1', 'attr2' => '2' } }
|
23
|
+
Crack::XML.parse(xml).should == hash
|
24
|
+
end
|
25
|
+
|
26
|
+
should "should transform repeating siblings into an array" do
|
27
|
+
xml =<<-XML
|
28
|
+
<opt>
|
29
|
+
<user login="grep" fullname="Gary R Epstein" />
|
30
|
+
<user login="stty" fullname="Simon T Tyson" />
|
31
|
+
</opt>
|
32
|
+
XML
|
33
|
+
|
34
|
+
Crack::XML.parse(xml)['opt']['user'].class.should == Array
|
35
|
+
|
36
|
+
hash = {
|
37
|
+
'opt' => {
|
38
|
+
'user' => [{
|
39
|
+
'login' => 'grep',
|
40
|
+
'fullname' => 'Gary R Epstein'
|
41
|
+
},{
|
42
|
+
'login' => 'stty',
|
43
|
+
'fullname' => 'Simon T Tyson'
|
44
|
+
}]
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
Crack::XML.parse(xml).should == hash
|
49
|
+
end
|
50
|
+
|
51
|
+
should "should not transform non-repeating siblings into an array" do
|
52
|
+
xml =<<-XML
|
53
|
+
<opt>
|
54
|
+
<user login="grep" fullname="Gary R Epstein" />
|
55
|
+
</opt>
|
56
|
+
XML
|
57
|
+
|
58
|
+
Crack::XML.parse(xml)['opt']['user'].class.should == Hash
|
59
|
+
|
60
|
+
hash = {
|
61
|
+
'opt' => {
|
62
|
+
'user' => {
|
63
|
+
'login' => 'grep',
|
64
|
+
'fullname' => 'Gary R Epstein'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
Crack::XML.parse(xml).should == hash
|
70
|
+
end
|
71
|
+
|
72
|
+
context "Parsing xml with text and attributes" do
|
73
|
+
setup do
|
74
|
+
xml =<<-XML
|
75
|
+
<opt>
|
76
|
+
<user login="grep">Gary R Epstein</user>
|
77
|
+
<user>Simon T Tyson</user>
|
78
|
+
</opt>
|
79
|
+
XML
|
80
|
+
@data = Crack::XML.parse(xml)
|
81
|
+
end
|
82
|
+
|
83
|
+
should "correctly parse text nodes" do
|
84
|
+
@data.should == {
|
85
|
+
'opt' => {
|
86
|
+
'user' => [
|
87
|
+
'Gary R Epstein',
|
88
|
+
'Simon T Tyson'
|
89
|
+
]
|
90
|
+
}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
should "be parse attributes for text node if present" do
|
95
|
+
@data['opt']['user'][0].attributes.should == {'login' => 'grep'}
|
96
|
+
end
|
97
|
+
|
98
|
+
should "default attributes to empty hash if not present" do
|
99
|
+
@data['opt']['user'][1].attributes.should == {}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
should "should typecast an integer" do
|
104
|
+
xml = "<tag type='integer'>10</tag>"
|
105
|
+
Crack::XML.parse(xml)['tag'].should == 10
|
106
|
+
end
|
107
|
+
|
108
|
+
should "should typecast a true boolean" do
|
109
|
+
xml = "<tag type='boolean'>true</tag>"
|
110
|
+
Crack::XML.parse(xml)['tag'].should be(true)
|
111
|
+
end
|
112
|
+
|
113
|
+
should "should typecast a false boolean" do
|
114
|
+
["false"].each do |w|
|
115
|
+
Crack::XML.parse("<tag type='boolean'>#{w}</tag>")['tag'].should be(false)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
should "should typecast a datetime" do
|
120
|
+
xml = "<tag type='datetime'>2007-12-31 10:32</tag>"
|
121
|
+
Crack::XML.parse(xml)['tag'].should == Time.parse( '2007-12-31 10:32' ).utc
|
122
|
+
end
|
123
|
+
|
124
|
+
should "should typecast a date" do
|
125
|
+
xml = "<tag type='date'>2007-12-31</tag>"
|
126
|
+
Crack::XML.parse(xml)['tag'].should == Date.parse('2007-12-31')
|
127
|
+
end
|
128
|
+
|
129
|
+
xml_entities = {
|
130
|
+
"<" => "<",
|
131
|
+
">" => ">",
|
132
|
+
'"' => """,
|
133
|
+
"'" => "'",
|
134
|
+
"&" => "&"
|
135
|
+
}
|
136
|
+
should "should unescape html entities" do
|
137
|
+
xml_entities.each do |k,v|
|
138
|
+
xml = "<tag>Some content #{v}</tag>"
|
139
|
+
Crack::XML.parse(xml)['tag'].should =~ Regexp.new(k)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
should "should unescape XML entities in attributes" do
|
144
|
+
xml_entities.each do |k,v|
|
145
|
+
xml = "<tag attr='Some content #{v}'></tag>"
|
146
|
+
Crack::XML.parse(xml)['tag']['attr'].should =~ Regexp.new(k)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
should "should undasherize keys as tags" do
|
151
|
+
xml = "<tag-1>Stuff</tag-1>"
|
152
|
+
Crack::XML.parse(xml).keys.should include( 'tag_1' )
|
153
|
+
end
|
154
|
+
|
155
|
+
should "should undasherize keys as attributes" do
|
156
|
+
xml = "<tag1 attr-1='1'></tag1>"
|
157
|
+
Crack::XML.parse(xml)['tag1'].keys.should include( 'attr_1')
|
158
|
+
end
|
159
|
+
|
160
|
+
should "should undasherize keys as tags and attributes" do
|
161
|
+
xml = "<tag-1 attr-1='1'></tag-1>"
|
162
|
+
Crack::XML.parse(xml).keys.should include( 'tag_1' )
|
163
|
+
Crack::XML.parse(xml)['tag_1'].keys.should include( 'attr_1')
|
164
|
+
end
|
165
|
+
|
166
|
+
should "should render nested content correctly" do
|
167
|
+
xml = "<root><tag1>Tag1 Content <em><strong>This is strong</strong></em></tag1></root>"
|
168
|
+
Crack::XML.parse(xml)['root']['tag1'].should == "Tag1 Content <em><strong>This is strong</strong></em>"
|
169
|
+
end
|
170
|
+
|
171
|
+
should "should render nested content with splshould text nodes correctly" do
|
172
|
+
xml = "<root>Tag1 Content<em>Stuff</em> Hi There</root>"
|
173
|
+
Crack::XML.parse(xml)['root'].should == "Tag1 Content<em>Stuff</em> Hi There"
|
174
|
+
end
|
175
|
+
|
176
|
+
should "should ignore attributes when a child is a text node" do
|
177
|
+
xml = "<root attr1='1'>Stuff</root>"
|
178
|
+
Crack::XML.parse(xml).should == { "root" => "Stuff" }
|
179
|
+
end
|
180
|
+
|
181
|
+
should "should ignore attributes when any child is a text node" do
|
182
|
+
xml = "<root attr1='1'>Stuff <em>in italics</em></root>"
|
183
|
+
Crack::XML.parse(xml).should == { "root" => "Stuff <em>in italics</em>" }
|
184
|
+
end
|
185
|
+
|
186
|
+
should "should correctly transform multiple children" do
|
187
|
+
xml = <<-XML
|
188
|
+
<user gender='m'>
|
189
|
+
<age type='integer'>35</age>
|
190
|
+
<name>Home Simpson</name>
|
191
|
+
<dob type='date'>1988-01-01</dob>
|
192
|
+
<joined-at type='datetime'>2000-04-28 23:01</joined-at>
|
193
|
+
<is-cool type='boolean'>true</is-cool>
|
194
|
+
</user>
|
195
|
+
XML
|
196
|
+
|
197
|
+
hash = {
|
198
|
+
"user" => {
|
199
|
+
"gender" => "m",
|
200
|
+
"age" => 35,
|
201
|
+
"name" => "Home Simpson",
|
202
|
+
"dob" => Date.parse('1988-01-01'),
|
203
|
+
"joined_at" => Time.parse("2000-04-28 23:01"),
|
204
|
+
"is_cool" => true
|
205
|
+
}
|
206
|
+
}
|
207
|
+
|
208
|
+
Crack::XML.parse(xml).should == hash
|
209
|
+
end
|
210
|
+
|
211
|
+
should "should properly handle nil values (ActiveSupport Compatible)" do
|
212
|
+
topic_xml = <<-EOT
|
213
|
+
<topic>
|
214
|
+
<title></title>
|
215
|
+
<id type="integer"></id>
|
216
|
+
<approved type="boolean"></approved>
|
217
|
+
<written-on type="date"></written-on>
|
218
|
+
<viewed-at type="datetime"></viewed-at>
|
219
|
+
<content type="yaml"></content>
|
220
|
+
<parent-id></parent-id>
|
221
|
+
</topic>
|
222
|
+
EOT
|
223
|
+
|
224
|
+
expected_topic_hash = {
|
225
|
+
'title' => nil,
|
226
|
+
'id' => nil,
|
227
|
+
'approved' => nil,
|
228
|
+
'written_on' => nil,
|
229
|
+
'viewed_at' => nil,
|
230
|
+
'content' => nil,
|
231
|
+
'parent_id' => nil
|
232
|
+
}
|
233
|
+
Crack::XML.parse(topic_xml)["topic"].should == expected_topic_hash
|
234
|
+
end
|
235
|
+
|
236
|
+
should "should handle a single record from xml (ActiveSupport Compatible)" do
|
237
|
+
topic_xml = <<-EOT
|
238
|
+
<topic>
|
239
|
+
<title>The First Topic</title>
|
240
|
+
<author-name>David</author-name>
|
241
|
+
<id type="integer">1</id>
|
242
|
+
<approved type="boolean"> true </approved>
|
243
|
+
<replies-count type="integer">0</replies-count>
|
244
|
+
<replies-close-in type="integer">2592000000</replies-close-in>
|
245
|
+
<written-on type="date">2003-07-16</written-on>
|
246
|
+
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
|
247
|
+
<content type="yaml">--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n</content>
|
248
|
+
<author-email-address>david@loudthinking.com</author-email-address>
|
249
|
+
<parent-id></parent-id>
|
250
|
+
<ad-revenue type="decimal">1.5</ad-revenue>
|
251
|
+
<optimum-viewing-angle type="float">135</optimum-viewing-angle>
|
252
|
+
<resident type="symbol">yes</resident>
|
253
|
+
</topic>
|
254
|
+
EOT
|
255
|
+
|
256
|
+
expected_topic_hash = {
|
257
|
+
'title' => "The First Topic",
|
258
|
+
'author_name' => "David",
|
259
|
+
'id' => 1,
|
260
|
+
'approved' => true,
|
261
|
+
'replies_count' => 0,
|
262
|
+
'replies_close_in' => 2592000000,
|
263
|
+
'written_on' => Date.new(2003, 7, 16),
|
264
|
+
'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
|
265
|
+
# Changed this line where the key is :message. The yaml specifies this as a symbol, and who am I to change what you specify
|
266
|
+
# The line in ActiveSupport is
|
267
|
+
# 'content' => { 'message' => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
|
268
|
+
'content' => { :message => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] },
|
269
|
+
'author_email_address' => "david@loudthinking.com",
|
270
|
+
'parent_id' => nil,
|
271
|
+
'ad_revenue' => BigDecimal("1.50"),
|
272
|
+
'optimum_viewing_angle' => 135.0,
|
273
|
+
'resident' => :yes
|
274
|
+
}
|
275
|
+
|
276
|
+
Crack::XML.parse(topic_xml)["topic"].each do |k,v|
|
277
|
+
v.should == expected_topic_hash[k]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
should "should handle multiple records (ActiveSupport Compatible)" do
|
282
|
+
topics_xml = <<-EOT
|
283
|
+
<topics type="array">
|
284
|
+
<topic>
|
285
|
+
<title>The First Topic</title>
|
286
|
+
<author-name>David</author-name>
|
287
|
+
<id type="integer">1</id>
|
288
|
+
<approved type="boolean">false</approved>
|
289
|
+
<replies-count type="integer">0</replies-count>
|
290
|
+
<replies-close-in type="integer">2592000000</replies-close-in>
|
291
|
+
<written-on type="date">2003-07-16</written-on>
|
292
|
+
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
|
293
|
+
<content>Have a nice day</content>
|
294
|
+
<author-email-address>david@loudthinking.com</author-email-address>
|
295
|
+
<parent-id nil="true"></parent-id>
|
296
|
+
</topic>
|
297
|
+
<topic>
|
298
|
+
<title>The Second Topic</title>
|
299
|
+
<author-name>Jason</author-name>
|
300
|
+
<id type="integer">1</id>
|
301
|
+
<approved type="boolean">false</approved>
|
302
|
+
<replies-count type="integer">0</replies-count>
|
303
|
+
<replies-close-in type="integer">2592000000</replies-close-in>
|
304
|
+
<written-on type="date">2003-07-16</written-on>
|
305
|
+
<viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at>
|
306
|
+
<content>Have a nice day</content>
|
307
|
+
<author-email-address>david@loudthinking.com</author-email-address>
|
308
|
+
<parent-id></parent-id>
|
309
|
+
</topic>
|
310
|
+
</topics>
|
311
|
+
EOT
|
312
|
+
|
313
|
+
expected_topic_hash = {
|
314
|
+
'title' => "The First Topic",
|
315
|
+
'author_name' => "David",
|
316
|
+
'id' => 1,
|
317
|
+
'approved' => false,
|
318
|
+
'replies_count' => 0,
|
319
|
+
'replies_close_in' => 2592000000,
|
320
|
+
'written_on' => Date.new(2003, 7, 16),
|
321
|
+
'viewed_at' => Time.utc(2003, 7, 16, 9, 28),
|
322
|
+
'content' => "Have a nice day",
|
323
|
+
'author_email_address' => "david@loudthinking.com",
|
324
|
+
'parent_id' => nil
|
325
|
+
}
|
326
|
+
# puts Crack::XML.parse(topics_xml)['topics'].first.inspect
|
327
|
+
Crack::XML.parse(topics_xml)["topics"].first.each do |k,v|
|
328
|
+
v.should == expected_topic_hash[k]
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
should "should handle a single record from_xml with attributes other than type (ActiveSupport Compatible)" do
|
333
|
+
topic_xml = <<-EOT
|
334
|
+
<rsp stat="ok">
|
335
|
+
<photos page="1" pages="1" perpage="100" total="16">
|
336
|
+
<photo id="175756086" owner="55569174@N00" secret="0279bf37a1" server="76" title="Colored Pencil PhotoBooth Fun" ispublic="1" isfriend="0" isfamily="0"/>
|
337
|
+
</photos>
|
338
|
+
</rsp>
|
339
|
+
EOT
|
340
|
+
|
341
|
+
expected_topic_hash = {
|
342
|
+
'id' => "175756086",
|
343
|
+
'owner' => "55569174@N00",
|
344
|
+
'secret' => "0279bf37a1",
|
345
|
+
'server' => "76",
|
346
|
+
'title' => "Colored Pencil PhotoBooth Fun",
|
347
|
+
'ispublic' => "1",
|
348
|
+
'isfriend' => "0",
|
349
|
+
'isfamily' => "0",
|
350
|
+
}
|
351
|
+
Crack::XML.parse(topic_xml)["rsp"]["photos"]["photo"].each do |k,v|
|
352
|
+
v.should == expected_topic_hash[k]
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
should "should handle an emtpy array (ActiveSupport Compatible)" do
|
357
|
+
blog_xml = <<-XML
|
358
|
+
<blog>
|
359
|
+
<posts type="array"></posts>
|
360
|
+
</blog>
|
361
|
+
XML
|
362
|
+
expected_blog_hash = {"blog" => {"posts" => []}}
|
363
|
+
Crack::XML.parse(blog_xml).should == expected_blog_hash
|
364
|
+
end
|
365
|
+
|
366
|
+
should "should handle empty array with whitespace from xml (ActiveSupport Compatible)" do
|
367
|
+
blog_xml = <<-XML
|
368
|
+
<blog>
|
369
|
+
<posts type="array">
|
370
|
+
</posts>
|
371
|
+
</blog>
|
372
|
+
XML
|
373
|
+
expected_blog_hash = {"blog" => {"posts" => []}}
|
374
|
+
Crack::XML.parse(blog_xml).should == expected_blog_hash
|
375
|
+
end
|
376
|
+
|
377
|
+
should "should handle array with one entry from_xml (ActiveSupport Compatible)" do
|
378
|
+
blog_xml = <<-XML
|
379
|
+
<blog>
|
380
|
+
<posts type="array">
|
381
|
+
<post>a post</post>
|
382
|
+
</posts>
|
383
|
+
</blog>
|
384
|
+
XML
|
385
|
+
expected_blog_hash = {"blog" => {"posts" => ["a post"]}}
|
386
|
+
Crack::XML.parse(blog_xml).should == expected_blog_hash
|
387
|
+
end
|
388
|
+
|
389
|
+
should "should handle array with multiple entries from xml (ActiveSupport Compatible)" do
|
390
|
+
blog_xml = <<-XML
|
391
|
+
<blog>
|
392
|
+
<posts type="array">
|
393
|
+
<post>a post</post>
|
394
|
+
<post>another post</post>
|
395
|
+
</posts>
|
396
|
+
</blog>
|
397
|
+
XML
|
398
|
+
expected_blog_hash = {"blog" => {"posts" => ["a post", "another post"]}}
|
399
|
+
Crack::XML.parse(blog_xml).should == expected_blog_hash
|
400
|
+
end
|
401
|
+
|
402
|
+
should "should handle file types (ActiveSupport Compatible)" do
|
403
|
+
blog_xml = <<-XML
|
404
|
+
<blog>
|
405
|
+
<logo type="file" name="logo.png" content_type="image/png">
|
406
|
+
</logo>
|
407
|
+
</blog>
|
408
|
+
XML
|
409
|
+
hash = Crack::XML.parse(blog_xml)
|
410
|
+
hash.keys.should include('blog')
|
411
|
+
hash['blog'].keys.should include('logo')
|
412
|
+
|
413
|
+
file = hash['blog']['logo']
|
414
|
+
file.original_filename.should == 'logo.png'
|
415
|
+
file.content_type.should == 'image/png'
|
416
|
+
end
|
417
|
+
|
418
|
+
should "should handle file from xml with defaults (ActiveSupport Compatible)" do
|
419
|
+
blog_xml = <<-XML
|
420
|
+
<blog>
|
421
|
+
<logo type="file">
|
422
|
+
</logo>
|
423
|
+
</blog>
|
424
|
+
XML
|
425
|
+
file = Crack::XML.parse(blog_xml)['blog']['logo']
|
426
|
+
file.original_filename.should == 'untitled'
|
427
|
+
file.content_type.should == 'application/octet-stream'
|
428
|
+
end
|
429
|
+
|
430
|
+
should "should handle xsd like types from xml (ActiveSupport Compatible)" do
|
431
|
+
bacon_xml = <<-EOT
|
432
|
+
<bacon>
|
433
|
+
<weight type="double">0.5</weight>
|
434
|
+
<price type="decimal">12.50</price>
|
435
|
+
<chunky type="boolean"> 1 </chunky>
|
436
|
+
<expires-at type="dateTime">2007-12-25T12:34:56+0000</expires-at>
|
437
|
+
<notes type="string"></notes>
|
438
|
+
<illustration type="base64Binary">YmFiZS5wbmc=</illustration>
|
439
|
+
</bacon>
|
440
|
+
EOT
|
441
|
+
|
442
|
+
expected_bacon_hash = {
|
443
|
+
'weight' => 0.5,
|
444
|
+
'chunky' => true,
|
445
|
+
'price' => BigDecimal("12.50"),
|
446
|
+
'expires_at' => Time.utc(2007,12,25,12,34,56),
|
447
|
+
'notes' => "",
|
448
|
+
'illustration' => "babe.png"
|
449
|
+
}
|
450
|
+
|
451
|
+
Crack::XML.parse(bacon_xml)["bacon"].should == expected_bacon_hash
|
452
|
+
end
|
453
|
+
|
454
|
+
should "should let type trickle through when unknown (ActiveSupport Compatible)" do
|
455
|
+
product_xml = <<-EOT
|
456
|
+
<product>
|
457
|
+
<weight type="double">0.5</weight>
|
458
|
+
<image type="ProductImage"><filename>image.gif</filename></image>
|
459
|
+
|
460
|
+
</product>
|
461
|
+
EOT
|
462
|
+
|
463
|
+
expected_product_hash = {
|
464
|
+
'weight' => 0.5,
|
465
|
+
'image' => {'type' => 'ProductImage', 'filename' => 'image.gif' },
|
466
|
+
}
|
467
|
+
|
468
|
+
Crack::XML.parse(product_xml)["product"].should == expected_product_hash
|
469
|
+
end
|
470
|
+
|
471
|
+
should "should handle unescaping from xml (ActiveResource Compatible)" do
|
472
|
+
xml_string = '<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>'
|
473
|
+
expected_hash = {
|
474
|
+
'bare_string' => 'First & Last Name',
|
475
|
+
'pre_escaped_string' => 'First & Last Name'
|
476
|
+
}
|
477
|
+
|
478
|
+
Crack::XML.parse(xml_string)['person'].should == expected_hash
|
479
|
+
end
|
480
|
+
|
481
|
+
should "handle an empty xml string" do
|
482
|
+
Crack::XML.parse('').should == {}
|
483
|
+
end
|
484
|
+
|
485
|
+
# As returned in the response body by the unfuddle XML API when creating objects
|
486
|
+
should "handle an xml string containing a single space" do
|
487
|
+
Crack::XML.parse(' ').should == {}
|
488
|
+
end
|
489
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
Dependencies
|
2
|
+
============
|
3
|
+
|
4
|
+
A simple way to express, manage and require your dependencies in Ruby.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Dependencies allows you to declare the list of libraries your application needs
|
10
|
+
with a simple, readable syntax. It comes with a handy command line
|
11
|
+
tool for inspecting and vendoring your dependencies.
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
Declare your dependencies in a `dependencies` file in the root of your project:
|
17
|
+
|
18
|
+
rack ~> 1.0
|
19
|
+
sinatra
|
20
|
+
webrat (test) git://github.com/brynary/webrat.git
|
21
|
+
quietbacktrace ~> 0.1
|
22
|
+
contest ~> 0.1 (test)
|
23
|
+
haml ~> 2.0
|
24
|
+
rack-test 0.3 (test)
|
25
|
+
faker ~> 0.3
|
26
|
+
spawn ~> 0.1
|
27
|
+
ohm git://github.com/soveran/ohm.git
|
28
|
+
|
29
|
+
Now you can try the `dep` command line tool to check your dependencies:
|
30
|
+
|
31
|
+
$ dep list
|
32
|
+
|
33
|
+
You can specify an environment to see if requirements are met:
|
34
|
+
|
35
|
+
$ dep list test
|
36
|
+
|
37
|
+
The above is `RACK_ENV`-aware.
|
38
|
+
|
39
|
+
Vendoring libraries
|
40
|
+
-------------------
|
41
|
+
|
42
|
+
In order to vendor a library you're using, simply:
|
43
|
+
|
44
|
+
$ dep vendor haml
|
45
|
+
|
46
|
+
If the dependency is expressed with a version number, it will be vendored using
|
47
|
+
`gem unpack`. Otherwise, it will try to clone from a Git repository.
|
48
|
+
|
49
|
+
It's common to vendor everything when you start a new project. Try this:
|
50
|
+
|
51
|
+
$ dep vendor --all
|
52
|
+
|
53
|
+
Loading dependencies in your project
|
54
|
+
------------------------------------
|
55
|
+
|
56
|
+
Dependencies doesn't assume you want to use RubyGems, so you're in charge of
|
57
|
+
requiring it before requiring `dependencies` (in Ruby 1.9 you're cornered – there's
|
58
|
+
no way out).
|
59
|
+
|
60
|
+
# init.rb
|
61
|
+
require "rubygems"
|
62
|
+
require "dependencies"
|
63
|
+
|
64
|
+
That will work as long as RubyGems is available and you have Dependencies installed.
|
65
|
+
If a dependency is not found in `./vendor`, a call to `#gem` will be made.
|
66
|
+
|
67
|
+
Another option is to vendor Dependencies itself:
|
68
|
+
|
69
|
+
# init.rb
|
70
|
+
require "vendor/dependencies/lib/dependencies"
|
71
|
+
|
72
|
+
After that, all your `lib` directories below `./vendor` will be available in the `$LOAD_PATH`.
|
73
|
+
|
74
|
+
Additionally, Dependencies will leave your `./lib` in the `$LOAD_PATH`.
|
75
|
+
|
76
|
+
Benefits
|
77
|
+
--------
|
78
|
+
|
79
|
+
1. Documentation. It's a text file any team member can read to see what the project depends on.
|
80
|
+
2. Early failure. If a dependency is not met, the program terminates with a polite message inviting you to install the missing dependencies.
|
81
|
+
3. Vendorability (™). Easily vendor everything for self-contained applications.
|
82
|
+
4. Simplicity. It's a very lightweight tool. It won't do everything, but it's simple and works very well for us.
|
83
|
+
|
84
|
+
Installation
|
85
|
+
------------
|
86
|
+
|
87
|
+
$ sudo gem install dependencies
|
88
|
+
|
89
|
+
License
|
90
|
+
-------
|
91
|
+
|
92
|
+
Copyright (c) 2009 Damian Janowski
|
93
|
+
|
94
|
+
Permission is hereby granted, free of charge, to any person
|
95
|
+
obtaining a copy of this software and associated documentation
|
96
|
+
files (the "Software"), to deal in the Software without
|
97
|
+
restriction, including without limitation the rights to use,
|
98
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
99
|
+
copies of the Software, and to permit persons to whom the
|
100
|
+
Software is furnished to do so, subject to the following
|
101
|
+
conditions:
|
102
|
+
|
103
|
+
The above copyright notice and this permission notice shall be
|
104
|
+
included in all copies or substantial portions of the Software.
|
105
|
+
|
106
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
107
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
108
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
109
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
110
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
111
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
112
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
113
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#! /usr/bin/env ruby -rubygems
|
2
|
+
|
3
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
4
|
+
|
5
|
+
require "fileutils"
|
6
|
+
require "dependencies/dep"
|
7
|
+
require "thor"
|
8
|
+
|
9
|
+
class App < Thor
|
10
|
+
include Thor::Actions
|
11
|
+
|
12
|
+
desc "list [ENV]", "lists dependencies"
|
13
|
+
def list(env = nil)
|
14
|
+
deps.filter(env).each { |dep| puts dep }
|
15
|
+
deps.require(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "vendor", "vendors the dependency to ./vendor"
|
19
|
+
method_options :all => :boolean
|
20
|
+
def vendor(name = nil)
|
21
|
+
name || options[:all] || flunk("No dependency given. Did you mean --all?")
|
22
|
+
|
23
|
+
if name
|
24
|
+
vendor_one(name)
|
25
|
+
else
|
26
|
+
vendor_all
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def vendor_one(name)
|
33
|
+
dep = dependency(name) || flunk("Dependency #{name} not found in dependencies.")
|
34
|
+
dep.version || dep.url || flunk("Don't know where to vendor #{name} from (no version or URL given...)")
|
35
|
+
|
36
|
+
FileUtils.mkdir("vendor") unless File.directory?("vendor")
|
37
|
+
|
38
|
+
inside "vendor", :verbose => true do
|
39
|
+
fetch dep
|
40
|
+
remove_file File.join(dep.name, ".git")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def vendor_all
|
45
|
+
prevent_exit do
|
46
|
+
deps.each do |dep|
|
47
|
+
vendor_one(dep.name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def fetch(dep)
|
53
|
+
if dep.version
|
54
|
+
run "gem unpack #{dep.name} -v #{dep.version}"
|
55
|
+
else
|
56
|
+
run "git clone #{dep.url} #{dep.name} -q --depth 1"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def deps
|
61
|
+
@deps ||= Dep.new(File.read("dependencies"))
|
62
|
+
rescue Errno::ENOENT
|
63
|
+
flunk "No dependencies file found."
|
64
|
+
end
|
65
|
+
|
66
|
+
def dependency(name)
|
67
|
+
deps.find { |dep| dep.name == name }
|
68
|
+
end
|
69
|
+
|
70
|
+
def flunk(message)
|
71
|
+
$stderr.puts(message)
|
72
|
+
exit 1 unless @prevent_exit
|
73
|
+
end
|
74
|
+
|
75
|
+
def prevent_exit
|
76
|
+
aux, @prevent_exit = @prevent_exit, false
|
77
|
+
yield
|
78
|
+
ensure
|
79
|
+
@prevent_exit = aux
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
App.start
|