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.
Files changed (245) hide show
  1. data/Rakefile +47 -0
  2. data/VERSION.yml +2 -2
  3. data/lib/core_ext/string.rb +6 -0
  4. data/lib/smoke/cache.rb +38 -23
  5. data/lib/smoke/request.rb +4 -8
  6. data/lib/smoke.rb +7 -2
  7. data/rdoc/classes/Smoke/Origin.html +340 -0
  8. data/rdoc/classes/Smoke/Source/Data.html +126 -0
  9. data/rdoc/classes/Smoke/Source/Feed.html +117 -0
  10. data/rdoc/classes/Smoke/Source/YQL.html +223 -0
  11. data/rdoc/classes/Smoke.html +260 -0
  12. data/rdoc/created.rid +1 -0
  13. data/rdoc/files/README_markdown.html +180 -0
  14. data/rdoc/files/lib/core_ext/hash_rb.html +49 -0
  15. data/rdoc/files/lib/smoke/origin_rb.html +49 -0
  16. data/rdoc/files/lib/smoke/request_rb.html +49 -0
  17. data/rdoc/files/lib/smoke/source/data_rb.html +49 -0
  18. data/rdoc/files/lib/smoke/source/feed_rb.html +49 -0
  19. data/rdoc/files/lib/smoke/source/join_rb.html +49 -0
  20. data/rdoc/files/lib/smoke/source/yql_rb.html +49 -0
  21. data/rdoc/files/lib/smoke_rb.html +65 -0
  22. data/rdoc/fr_class_index.html +21 -0
  23. data/rdoc/fr_file_index.html +28 -0
  24. data/rdoc/fr_method_index.html +4459 -0
  25. data/rdoc/index.html +15 -0
  26. data/rdoc/rdoc-style.css +319 -0
  27. data/spec/smoke/cache_spec.rb +28 -6
  28. data/vendor/crack/History +15 -0
  29. data/vendor/crack/LICENSE +20 -0
  30. data/vendor/crack/README.rdoc +42 -0
  31. data/vendor/crack/Rakefile +49 -0
  32. data/vendor/crack/VERSION.yml +4 -0
  33. data/vendor/crack/crack.gemspec +61 -0
  34. data/vendor/crack/lib/crack/core_extensions.rb +128 -0
  35. data/vendor/crack/lib/crack/json.rb +68 -0
  36. data/vendor/crack/lib/crack/xml.rb +214 -0
  37. data/vendor/crack/lib/crack.rb +7 -0
  38. data/vendor/crack/test/crack_test.rb +4 -0
  39. data/vendor/crack/test/data/twittersearch-firefox.json +1 -0
  40. data/vendor/crack/test/data/twittersearch-ie.json +1 -0
  41. data/vendor/crack/test/hash_test.rb +56 -0
  42. data/vendor/crack/test/json_test.rb +66 -0
  43. data/vendor/crack/test/string_test.rb +31 -0
  44. data/vendor/crack/test/test_helper.rb +12 -0
  45. data/vendor/crack/test/xml_test.rb +489 -0
  46. data/vendor/dependencies/README.markdown +113 -0
  47. data/vendor/dependencies/Rakefile +5 -0
  48. data/vendor/dependencies/bin/dep +83 -0
  49. data/vendor/dependencies/dependencies.gemspec +15 -0
  50. data/vendor/dependencies/dependencies.gemspec.erb +27 -0
  51. data/vendor/dependencies/lib/dependencies/dep.rb +99 -0
  52. data/vendor/dependencies/lib/dependencies.rb +5 -0
  53. data/vendor/dependencies/test/dependencies_test.rb +228 -0
  54. data/vendor/dependencies/test/foobaz-0.3.gem +0 -0
  55. data/vendor/fakeweb/CHANGELOG +163 -0
  56. data/vendor/fakeweb/LICENSE.txt +281 -0
  57. data/vendor/fakeweb/README.rdoc +193 -0
  58. data/vendor/fakeweb/Rakefile +76 -0
  59. data/vendor/fakeweb/fakeweb.gemspec +21 -0
  60. data/vendor/fakeweb/lib/fake_web/ext/net_http.rb +71 -0
  61. data/vendor/fakeweb/lib/fake_web/registry.rb +103 -0
  62. data/vendor/fakeweb/lib/fake_web/responder.rb +113 -0
  63. data/vendor/fakeweb/lib/fake_web/response.rb +10 -0
  64. data/vendor/fakeweb/lib/fake_web/stub_socket.rb +15 -0
  65. data/vendor/fakeweb/lib/fake_web/utility.rb +22 -0
  66. data/vendor/fakeweb/lib/fake_web.rb +172 -0
  67. data/vendor/fakeweb/lib/fakeweb.rb +2 -0
  68. data/vendor/fakeweb/test/fixtures/google_response_from_curl +12 -0
  69. data/vendor/fakeweb/test/fixtures/google_response_with_transfer_encoding +17 -0
  70. data/vendor/fakeweb/test/fixtures/google_response_without_transfer_encoding +11 -0
  71. data/vendor/fakeweb/test/fixtures/test_example.txt +1 -0
  72. data/vendor/fakeweb/test/fixtures/test_txt_file +3 -0
  73. data/vendor/fakeweb/test/test_allow_net_connect.rb +85 -0
  74. data/vendor/fakeweb/test/test_deprecations.rb +54 -0
  75. data/vendor/fakeweb/test/test_fake_authentication.rb +92 -0
  76. data/vendor/fakeweb/test/test_fake_web.rb +535 -0
  77. data/vendor/fakeweb/test/test_fake_web_open_uri.rb +58 -0
  78. data/vendor/fakeweb/test/test_helper.rb +74 -0
  79. data/vendor/fakeweb/test/test_missing_open_uri.rb +25 -0
  80. data/vendor/fakeweb/test/test_precedence.rb +51 -0
  81. data/vendor/fakeweb/test/test_query_string.rb +45 -0
  82. data/vendor/fakeweb/test/test_regexes.rb +103 -0
  83. data/vendor/fakeweb/test/test_response_headers.rb +73 -0
  84. data/vendor/fakeweb/test/test_trailing_slashes.rb +53 -0
  85. data/vendor/fakeweb/test/test_utility.rb +70 -0
  86. data/vendor/json-1.1.3/CHANGES +93 -0
  87. data/vendor/json-1.1.3/GPL +340 -0
  88. data/vendor/json-1.1.3/README +78 -0
  89. data/vendor/json-1.1.3/RUBY +58 -0
  90. data/vendor/json-1.1.3/Rakefile +309 -0
  91. data/vendor/json-1.1.3/TODO +1 -0
  92. data/vendor/json-1.1.3/VERSION +1 -0
  93. data/vendor/json-1.1.3/benchmarks/benchmark.txt +133 -0
  94. data/vendor/json-1.1.3/benchmarks/benchmark_generator.rb +48 -0
  95. data/vendor/json-1.1.3/benchmarks/benchmark_parser.rb +26 -0
  96. data/vendor/json-1.1.3/benchmarks/benchmark_rails.rb +26 -0
  97. data/vendor/json-1.1.3/bin/edit_json.rb +10 -0
  98. data/vendor/json-1.1.3/bin/prettify_json.rb +76 -0
  99. data/vendor/json-1.1.3/data/example.json +1 -0
  100. data/vendor/json-1.1.3/data/index.html +38 -0
  101. data/vendor/json-1.1.3/data/prototype.js +4184 -0
  102. data/vendor/json-1.1.3/ext/json/ext/generator/extconf.rb +9 -0
  103. data/vendor/json-1.1.3/ext/json/ext/generator/generator.c +875 -0
  104. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.c +182 -0
  105. data/vendor/json-1.1.3/ext/json/ext/generator/unicode.h +53 -0
  106. data/vendor/json-1.1.3/ext/json/ext/parser/extconf.rb +9 -0
  107. data/vendor/json-1.1.3/ext/json/ext/parser/parser.c +1758 -0
  108. data/vendor/json-1.1.3/ext/json/ext/parser/parser.rl +638 -0
  109. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.c +154 -0
  110. data/vendor/json-1.1.3/ext/json/ext/parser/unicode.h +58 -0
  111. data/vendor/json-1.1.3/install.rb +26 -0
  112. data/vendor/json-1.1.3/lib/json/Array.xpm +21 -0
  113. data/vendor/json-1.1.3/lib/json/FalseClass.xpm +21 -0
  114. data/vendor/json-1.1.3/lib/json/Hash.xpm +21 -0
  115. data/vendor/json-1.1.3/lib/json/Key.xpm +73 -0
  116. data/vendor/json-1.1.3/lib/json/NilClass.xpm +21 -0
  117. data/vendor/json-1.1.3/lib/json/Numeric.xpm +28 -0
  118. data/vendor/json-1.1.3/lib/json/String.xpm +96 -0
  119. data/vendor/json-1.1.3/lib/json/TrueClass.xpm +21 -0
  120. data/vendor/json-1.1.3/lib/json/add/core.rb +135 -0
  121. data/vendor/json-1.1.3/lib/json/add/rails.rb +58 -0
  122. data/vendor/json-1.1.3/lib/json/common.rb +354 -0
  123. data/vendor/json-1.1.3/lib/json/editor.rb +1362 -0
  124. data/vendor/json-1.1.3/lib/json/ext.rb +13 -0
  125. data/vendor/json-1.1.3/lib/json/json.xpm +1499 -0
  126. data/vendor/json-1.1.3/lib/json/pure/generator.rb +394 -0
  127. data/vendor/json-1.1.3/lib/json/pure/parser.rb +259 -0
  128. data/vendor/json-1.1.3/lib/json/pure.rb +75 -0
  129. data/vendor/json-1.1.3/lib/json/version.rb +9 -0
  130. data/vendor/json-1.1.3/lib/json.rb +235 -0
  131. data/vendor/json-1.1.3/tests/fixtures/fail1.json +1 -0
  132. data/vendor/json-1.1.3/tests/fixtures/fail10.json +1 -0
  133. data/vendor/json-1.1.3/tests/fixtures/fail11.json +1 -0
  134. data/vendor/json-1.1.3/tests/fixtures/fail12.json +1 -0
  135. data/vendor/json-1.1.3/tests/fixtures/fail13.json +1 -0
  136. data/vendor/json-1.1.3/tests/fixtures/fail14.json +1 -0
  137. data/vendor/json-1.1.3/tests/fixtures/fail18.json +1 -0
  138. data/vendor/json-1.1.3/tests/fixtures/fail19.json +1 -0
  139. data/vendor/json-1.1.3/tests/fixtures/fail2.json +1 -0
  140. data/vendor/json-1.1.3/tests/fixtures/fail20.json +1 -0
  141. data/vendor/json-1.1.3/tests/fixtures/fail21.json +1 -0
  142. data/vendor/json-1.1.3/tests/fixtures/fail22.json +1 -0
  143. data/vendor/json-1.1.3/tests/fixtures/fail23.json +1 -0
  144. data/vendor/json-1.1.3/tests/fixtures/fail24.json +1 -0
  145. data/vendor/json-1.1.3/tests/fixtures/fail25.json +1 -0
  146. data/vendor/json-1.1.3/tests/fixtures/fail27.json +2 -0
  147. data/vendor/json-1.1.3/tests/fixtures/fail28.json +2 -0
  148. data/vendor/json-1.1.3/tests/fixtures/fail3.json +1 -0
  149. data/vendor/json-1.1.3/tests/fixtures/fail4.json +1 -0
  150. data/vendor/json-1.1.3/tests/fixtures/fail5.json +1 -0
  151. data/vendor/json-1.1.3/tests/fixtures/fail6.json +1 -0
  152. data/vendor/json-1.1.3/tests/fixtures/fail7.json +1 -0
  153. data/vendor/json-1.1.3/tests/fixtures/fail8.json +1 -0
  154. data/vendor/json-1.1.3/tests/fixtures/fail9.json +1 -0
  155. data/vendor/json-1.1.3/tests/fixtures/pass1.json +56 -0
  156. data/vendor/json-1.1.3/tests/fixtures/pass15.json +1 -0
  157. data/vendor/json-1.1.3/tests/fixtures/pass16.json +1 -0
  158. data/vendor/json-1.1.3/tests/fixtures/pass17.json +1 -0
  159. data/vendor/json-1.1.3/tests/fixtures/pass2.json +1 -0
  160. data/vendor/json-1.1.3/tests/fixtures/pass26.json +1 -0
  161. data/vendor/json-1.1.3/tests/fixtures/pass3.json +6 -0
  162. data/vendor/json-1.1.3/tests/runner.rb +25 -0
  163. data/vendor/json-1.1.3/tests/test_json.rb +293 -0
  164. data/vendor/json-1.1.3/tests/test_json_addition.rb +161 -0
  165. data/vendor/json-1.1.3/tests/test_json_fixtures.rb +30 -0
  166. data/vendor/json-1.1.3/tests/test_json_generate.rb +100 -0
  167. data/vendor/json-1.1.3/tests/test_json_rails.rb +118 -0
  168. data/vendor/json-1.1.3/tests/test_json_unicode.rb +61 -0
  169. data/vendor/json-1.1.3/tools/fuzz.rb +140 -0
  170. data/vendor/json-1.1.3/tools/server.rb +62 -0
  171. data/vendor/moneta/LICENSE +20 -0
  172. data/vendor/moneta/README +51 -0
  173. data/vendor/moneta/Rakefile +60 -0
  174. data/vendor/moneta/TODO +4 -0
  175. data/vendor/moneta/benchmarks/various.rb +234 -0
  176. data/vendor/moneta/lib/moneta/basic_file.rb +111 -0
  177. data/vendor/moneta/lib/moneta/berkeley.rb +53 -0
  178. data/vendor/moneta/lib/moneta/couch.rb +63 -0
  179. data/vendor/moneta/lib/moneta/datamapper.rb +117 -0
  180. data/vendor/moneta/lib/moneta/file.rb +91 -0
  181. data/vendor/moneta/lib/moneta/lmc.rb +52 -0
  182. data/vendor/moneta/lib/moneta/memcache.rb +53 -0
  183. data/vendor/moneta/lib/moneta/memory.rb +11 -0
  184. data/vendor/moneta/lib/moneta/mongodb.rb +58 -0
  185. data/vendor/moneta/lib/moneta/redis.rb +49 -0
  186. data/vendor/moneta/lib/moneta/rufus.rb +41 -0
  187. data/vendor/moneta/lib/moneta/s3.rb +162 -0
  188. data/vendor/moneta/lib/moneta/sdbm.rb +33 -0
  189. data/vendor/moneta/lib/moneta/tyrant.rb +58 -0
  190. data/vendor/moneta/lib/moneta/xattr.rb +58 -0
  191. data/vendor/moneta/lib/moneta.rb +76 -0
  192. data/vendor/moneta/moneta.gemspec +32 -0
  193. data/vendor/moneta/script/destroy +14 -0
  194. data/vendor/moneta/script/generate +14 -0
  195. data/vendor/moneta/spec/moneta_basic_file_spec.rb +50 -0
  196. data/vendor/moneta/spec/moneta_berkeley_spec.rb +20 -0
  197. data/vendor/moneta/spec/moneta_couch_spec.rb +22 -0
  198. data/vendor/moneta/spec/moneta_datamapper_spec.rb +79 -0
  199. data/vendor/moneta/spec/moneta_file_spec.rb +21 -0
  200. data/vendor/moneta/spec/moneta_lmc_spec.rb +24 -0
  201. data/vendor/moneta/spec/moneta_memcache_spec.rb +16 -0
  202. data/vendor/moneta/spec/moneta_memory_spec.rb +12 -0
  203. data/vendor/moneta/spec/moneta_mongodb_spec.rb +16 -0
  204. data/vendor/moneta/spec/moneta_redis_spec.rb +16 -0
  205. data/vendor/moneta/spec/moneta_rufus_spec.rb +15 -0
  206. data/vendor/moneta/spec/moneta_s3_spec.rb +19 -0
  207. data/vendor/moneta/spec/moneta_sdbm_spec.rb +21 -0
  208. data/vendor/moneta/spec/moneta_tyrant_spec.rb +15 -0
  209. data/vendor/moneta/spec/moneta_xattr_spec.rb +21 -0
  210. data/vendor/moneta/spec/shared.rb +122 -0
  211. data/vendor/moneta/spec/spec_helper.rb +7 -0
  212. data/vendor/rest-client/README.rdoc +151 -0
  213. data/vendor/rest-client/Rakefile +58 -0
  214. data/vendor/rest-client/VERSION +1 -0
  215. data/vendor/rest-client/bin/restclient +87 -0
  216. data/vendor/rest-client/lib/rest_client.rb +2 -0
  217. data/vendor/rest-client/lib/restclient/exceptions.rb +88 -0
  218. data/vendor/rest-client/lib/restclient/mixin/response.rb +43 -0
  219. data/vendor/rest-client/lib/restclient/raw_response.rb +30 -0
  220. data/vendor/rest-client/lib/restclient/request.rb +238 -0
  221. data/vendor/rest-client/lib/restclient/resource.rb +146 -0
  222. data/vendor/rest-client/lib/restclient/response.rb +20 -0
  223. data/vendor/rest-client/lib/restclient.rb +99 -0
  224. data/vendor/rest-client/rest-client.gemspec +66 -0
  225. data/vendor/rest-client/spec/base.rb +4 -0
  226. data/vendor/rest-client/spec/exceptions_spec.rb +65 -0
  227. data/vendor/rest-client/spec/mixin/response_spec.rb +46 -0
  228. data/vendor/rest-client/spec/raw_response_spec.rb +17 -0
  229. data/vendor/rest-client/spec/request_spec.rb +476 -0
  230. data/vendor/rest-client/spec/resource_spec.rb +75 -0
  231. data/vendor/rest-client/spec/response_spec.rb +16 -0
  232. data/vendor/rest-client/spec/restclient_spec.rb +53 -0
  233. data/vendor/simple-rss/LICENSE +429 -0
  234. data/vendor/simple-rss/README +43 -0
  235. data/vendor/simple-rss/Rakefile +212 -0
  236. data/vendor/simple-rss/install.rb +40 -0
  237. data/vendor/simple-rss/lib/simple-rss.rb +150 -0
  238. data/vendor/simple-rss/simple-rss.gemspec +12 -0
  239. data/vendor/simple-rss/test/base/base_test.rb +51 -0
  240. data/vendor/simple-rss/test/data/atom.xml +45 -0
  241. data/vendor/simple-rss/test/data/not-rss.xml +8 -0
  242. data/vendor/simple-rss/test/data/rss09.rdf +79 -0
  243. data/vendor/simple-rss/test/data/rss20.xml +818 -0
  244. data/vendor/simple-rss/test/test_helper.rb +4 -0
  245. metadata +314 -40
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "smoke"
9
+ gem.summary = %Q{smoke is a DSL that allows you to take data from YQL, RSS / Atom}
10
+ gem.email = "ben.schwarz@gmail.com"
11
+ gem.homepage = "http://github.com/benschwarz/smoke"
12
+ gem.authors = ["Ben Schwarz"]
13
+ gem.files = FileList['lib/**/*.rb', 'rdoc/**/*', '[A-Z]*', 'spec/**/*', 'vendor/**/*'].to_a
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ begin
21
+ gem 'mislav-hanna', '>= 0.2.7'
22
+ require 'hanna/rdoctask'
23
+ rescue LoadError
24
+ require 'rake/rdoctask'
25
+ end
26
+ Rake::RDocTask.new do |rdoc|
27
+ rdoc.rdoc_dir = 'rdoc'
28
+ rdoc.title = 'smoke'
29
+ rdoc.options << '--line-numbers' << '--inline-source'
30
+ rdoc.rdoc_files.include('README*')
31
+ rdoc.rdoc_files.include('lib/**/*.rb')
32
+ end
33
+
34
+ require 'spec/rake/spectask'
35
+ Spec::Rake::SpecTask.new(:test) do |t|
36
+ t.spec_opts = ['--options', "spec/spec.opts"]
37
+ t.spec_files = FileList['spec/**/*_spec.rb']
38
+ end
39
+
40
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
41
+ spec.libs << 'lib' << 'spec'
42
+ spec.pattern = 'spec/**/*_spec.rb'
43
+ spec.rcov = true
44
+ end
45
+
46
+ task :spec => :test
47
+ task :default => :test
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 4
4
+ :minor: 5
@@ -0,0 +1,6 @@
1
+ class String
2
+ def camel_case
3
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
4
+ split('_').map{|e| e.capitalize}.join
5
+ end
6
+ end
data/lib/smoke/cache.rb CHANGED
@@ -4,40 +4,55 @@ require 'digest/md5'
4
4
  module Smoke
5
5
  class Cache
6
6
  class << self
7
- def configure!
8
- require "moneta/#{Smoke.config[:cache][:store].to_s}" if enabled?
9
- rescue LoadError
10
- Smoke.log.fatal "Cache store not found. Smoke uses moneta for cache stores, ensure that you've chosen a moneta supported store"
11
- end
12
-
13
- def fetch(name, &block)
14
- key = generate_key(name)
15
- output = (enabled?) ? cache[key] : block.call
16
- if output
17
- return output
18
- else
19
- output = block.call
20
- persist(key, output)
7
+ def fetch(uri, options)
8
+ output = (enabled?) ? read(uri) : query(uri, options)
9
+
10
+ unless output.keys.any?
11
+ Smoke.log.info "Cache miss"
12
+ output = query(uri, options)
21
13
  end
22
-
23
- return output
14
+
15
+ output
16
+ rescue
17
+ query(uri, options)
24
18
  end
25
-
19
+
26
20
  def enabled?
27
21
  Smoke.config[:cache][:enabled]
28
22
  end
29
23
 
30
- private
24
+ protected
31
25
  def cache
32
- Moneta.const_get(Smoke.config[:cache][:store]).send(:new, Smoke.config[:cache][:options])
26
+ Moneta.autoload(klass_name.to_sym, file_name)
27
+ @@cache ||= Moneta.const_get(klass_name).new(Smoke.config[:cache][:options])
33
28
  end
34
-
35
- def persist(key, store)
36
- cache.store(key, store, :expire_in => Smoke.config[:config][:cache][:expiry])
29
+
30
+ def file_name
31
+ "moneta/#{Smoke.config[:cache][:store].to_s}"
32
+ end
33
+
34
+ def klass_name
35
+ Smoke.config[:cache][:store].to_s.camel_case
36
+ end
37
+
38
+ def query(uri, options)
39
+ request = RestClient.get(uri, options)
40
+ write(uri, request, request.headers[:content_type]) if enabled?
41
+ {:body => request, :content_type => request.headers[:content_type]}
42
+ end
43
+
44
+ def read(uri)
45
+ key = generate_key(uri)
46
+ return cache[key]
47
+ end
48
+
49
+ def write(uri, body, content_type)
50
+ store = {:body => body, :content_type => content_type}
51
+ self.cache.store(generate_key(uri), store, :expire_in => Smoke.config[:cache][:expiry])
37
52
  end
38
53
 
39
54
  def generate_key(key)
40
- Digest::MD5.hexdigest(key)
55
+ Digest::MD5.hexdigest(key.to_s)
41
56
  end
42
57
  end
43
58
  end
data/lib/smoke/request.rb CHANGED
@@ -23,14 +23,10 @@ module Smoke
23
23
  end
24
24
 
25
25
  private
26
- def dispatch
27
- Smoke::Cache.fetch @uri do
28
- Thread.new {
29
- request = RestClient.get(@uri, @@request_options)
30
- @content_type = request.headers[:content_type]
31
- @body = request
32
- }.join
33
- end
26
+ def dispatch
27
+ get = Smoke::Cache.fetch @uri, @@request_options
28
+ @body = get[:body]
29
+ @content_type = get[:content_type]
34
30
 
35
31
  present! unless @options[:raw_response]
36
32
 
data/lib/smoke.rb CHANGED
@@ -1,3 +1,9 @@
1
+ begin
2
+ require "vendor/dependencies/lib/dependencies"
3
+ rescue LoadError
4
+ require "dependencies"
5
+ end
6
+
1
7
  require 'restclient'
2
8
  require 'logger'
3
9
  require 'crack'
@@ -71,7 +77,6 @@ module Smoke
71
77
  #
72
78
  def configure(&block)
73
79
  yield @@config
74
- Smoke::Cache.configure!
75
80
  end
76
81
 
77
82
  # Access configuration options
@@ -96,7 +101,7 @@ module Smoke
96
101
  end
97
102
  end
98
103
 
99
- %w(core_ext/hash smoke/cache smoke/request smoke/origin).each {|r| require File.join(File.dirname(__FILE__), r)}
104
+ %w(core_ext/hash core_ext/string smoke/cache smoke/request smoke/origin).each {|r| require File.join(File.dirname(__FILE__), r)}
100
105
 
101
106
  class Object # :nodoc:
102
107
  include Smoke
@@ -0,0 +1,340 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html lang='en'>
3
+ <head>
4
+ <title>: Smoke::Origin [smoke]</title>
5
+ <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
6
+ <link href='../../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
7
+ <script type='text/javascript'>
8
+ //<![CDATA[
9
+ function popupCode(url) {
10
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
11
+ }
12
+
13
+ function toggleCode(id) {
14
+ var code = document.getElementById(id)
15
+
16
+ code.style.display = code.style.display != 'block' ? 'block' : 'none'
17
+ return true
18
+ }
19
+
20
+ // Make codeblocks hidden by default
21
+ document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
22
+ //]]>
23
+ </script>
24
+ </head>
25
+ <body class='page'>
26
+ <div class='class' id='wrapper'>
27
+ <div class='header'>
28
+ <h1 class='name'>
29
+ <span class='type'>Class</span>
30
+ Smoke::Origin
31
+ </h1>
32
+ <ol class='paths'>
33
+ <li>
34
+ <a href="../../files/lib/smoke/origin_rb.html">lib/smoke/origin.rb</a>
35
+ </li>
36
+ </ol>
37
+ <div class='parent'>
38
+ Parent:
39
+ <strong>Object</strong>
40
+ </div>
41
+ </div>
42
+ <div id='content'>
43
+ <div id='text'>
44
+ <div id='method-list'>
45
+ <h2>Methods</h2>
46
+ <h3>public class</h3>
47
+ <ol>
48
+ <li><a href="#M000020">new</a></li>
49
+ </ol>
50
+ <h3>public instance</h3>
51
+ <ol>
52
+ <li><a href="#M000028">discard</a></li>
53
+ <li><a href="#M000023">emit</a></li>
54
+ <li><a href="#M000027">keep</a></li>
55
+ <li><a href="#M000025">method_missing</a></li>
56
+ <li><a href="#M000021">output</a></li>
57
+ <li><a href="#M000022">path</a></li>
58
+ <li><a href="#M000024">prepare</a></li>
59
+ <li><a href="#M000029">rename</a></li>
60
+ <li><a href="#M000026">sort</a></li>
61
+ <li><a href="#M000030">truncate</a></li>
62
+ </ol>
63
+ </div>
64
+ <div id='section'>
65
+ <div id='attribute-list'>
66
+ <h2 class='section-bar'>Attributes</h2>
67
+ <div class='name-list'>
68
+ <table>
69
+ <tr class='top-aligned-row context-row'>
70
+ <td class='context-item-name'>items</td>
71
+ <td class='context-item-value'>[R]</td>
72
+ <td class='context-item-desc'></td>
73
+ </tr>
74
+ <tr class='top-aligned-row context-row'>
75
+ <td class='context-item-name'>name</td>
76
+ <td class='context-item-value'>[RW]</td>
77
+ <td class='context-item-desc'></td>
78
+ </tr>
79
+ </table>
80
+ </div>
81
+ </div>
82
+ <div id='methods'>
83
+ <h2>Public class methods</h2>
84
+ <div class='public-class method' id='method-M000020'>
85
+ <a name='M000020'> </a>
86
+ <div class='synopsis'>
87
+ <span class='name'>new</span>
88
+ <span class='arguments'>(name, &amp;block)</span>
89
+ </div>
90
+ <div class='source'>
91
+ <a class='source-toggle' href='#' onclick="toggleCode('M000020-source'); return false">
92
+ [show source]
93
+ </a>
94
+ <pre id='M000020-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 6</span>&#x000A; 6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)&#x000A; 7: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-value str">&quot;Sources must have a name&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">name</span>&#x000A; 8: <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">name</span>&#x000A; 9: <span class="ruby-ivar">@items</span>, <span class="ruby-ivar">@prepare</span>, <span class="ruby-ivar">@transformation</span> = [], [], []&#x000A;10: &#x000A;11: <span class="ruby-identifier">activate!</span>&#x000A;12: <span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>&#x000A;13: <span class="ruby-keyword kw">end</span></pre>
95
+ </div>
96
+ </div>
97
+ <h2>Public instance methods</h2>
98
+ <div class='public-instance method' id='method-M000028'>
99
+ <a name='M000028'> </a>
100
+ <div class='synopsis'>
101
+ <span class='name'>discard</span>
102
+ <span class='arguments'>(key, matcher)</span>
103
+ </div>
104
+ <div class='description'>
105
+ <p>
106
+ Discard items that do not match the regex
107
+ </p>
108
+ <p>
109
+ Usage (chained):
110
+ </p>
111
+ <pre>Smoke[:ruby].discard(:title, /tuesday/i)</pre>
112
+ <p>
113
+ Usage (block, during initialization):
114
+ </p>
115
+ <pre>Smoke.yql(:ruby) do&#x000A; ...&#x000A; discard(:title, /tuesday/i)&#x000A;end</pre>
116
+ </div>
117
+ <div class='source'>
118
+ <a class='source-toggle' href='#' onclick="toggleCode('M000028-source'); return false">
119
+ [show source]
120
+ </a>
121
+ <pre id='M000028-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 140</span>&#x000A;140: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discard</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">matcher</span>)&#x000A;141: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">reject!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">=~</span> <span class="ruby-identifier">matcher</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span> }&#x000A;142: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;143: <span class="ruby-keyword kw">end</span></pre>
122
+ </div>
123
+ </div>
124
+ <div class='public-instance method' id='method-M000023'>
125
+ <a name='M000023'> </a>
126
+ <div class='synopsis'>
127
+ <span class='name'>emit</span>
128
+ <span class='arguments'>(&amp;block)</span>
129
+ </div>
130
+ <div class='description'>
131
+ <p>
132
+ Transform each item
133
+ </p>
134
+ <p>
135
+ Usage:
136
+ </p>
137
+ <pre>emit do&#x000A; rename(:href =&gt; :link)&#x000A;end</pre>
138
+ </div>
139
+ <div class='source'>
140
+ <a class='source-toggle' href='#' onclick="toggleCode('M000023-source'); return false">
141
+ [show source]
142
+ </a>
143
+ <pre id='M000023-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 72</span>&#x000A;72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">emit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)&#x000A;73: <span class="ruby-ivar">@transformation</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">block</span>&#x000A;74: <span class="ruby-keyword kw">end</span></pre>
144
+ </div>
145
+ </div>
146
+ <div class='public-instance method' id='method-M000027'>
147
+ <a name='M000027'> </a>
148
+ <div class='synopsis'>
149
+ <span class='name'>keep</span>
150
+ <span class='arguments'>(key, matcher)</span>
151
+ </div>
152
+ <div class='description'>
153
+ <p>
154
+ Keep items that match the regex
155
+ </p>
156
+ <p>
157
+ Usage (chained):
158
+ </p>
159
+ <pre>Smoke[:ruby].keep(:title, /tuesday/i)</pre>
160
+ <p>
161
+ Usage (block, during initialization):
162
+ </p>
163
+ <pre>Smoke.yql(:ruby) do&#x000A; ...&#x000A; keep(:title, /tuesday/i)&#x000A;end</pre>
164
+ </div>
165
+ <div class='source'>
166
+ <a class='source-toggle' href='#' onclick="toggleCode('M000027-source'); return false">
167
+ [show source]
168
+ </a>
169
+ <pre id='M000027-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 126</span>&#x000A;126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">keep</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">matcher</span>)&#x000A;127: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">reject!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] <span class="ruby-operator">=~</span> <span class="ruby-identifier">matcher</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">true</span> }&#x000A;128: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;129: <span class="ruby-keyword kw">end</span></pre>
170
+ </div>
171
+ </div>
172
+ <div class='public-instance method' id='method-M000025'>
173
+ <a name='M000025'> </a>
174
+ <div class='synopsis'>
175
+ <span class='name'>method_missing</span>
176
+ <span class='arguments'>(symbol, *args, &amp;block)</span>
177
+ </div>
178
+ <div class='source'>
179
+ <a class='source-toggle' href='#' onclick="toggleCode('M000025-source'); return false">
180
+ [show source]
181
+ </a>
182
+ <pre id='M000025-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 96</span>&#x000A; 96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">symbol</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)&#x000A; 97: <span class="ruby-identifier">ivar</span> = <span class="ruby-node">&quot;@#{symbol}&quot;</span>&#x000A; 98: &#x000A; 99: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>&#x000A;100: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">ivar</span>) <span class="ruby-operator">||</span> <span class="ruby-keyword kw">super</span> &#x000A;101: <span class="ruby-keyword kw">else</span>&#x000A;102: <span class="ruby-identifier">instance_variable_set</span>(<span class="ruby-identifier">ivar</span>, <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span>)&#x000A;103: <span class="ruby-keyword kw">end</span>&#x000A;104: &#x000A;105: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;106: <span class="ruby-keyword kw">end</span></pre>
183
+ </div>
184
+ </div>
185
+ <div class='public-instance method' id='method-M000021'>
186
+ <a name='M000021'> </a>
187
+ <div class='synopsis'>
188
+ <span class='name'>output</span>
189
+ <span class='arguments'>(type = :ruby)</span>
190
+ </div>
191
+ <div class='description'>
192
+ <p>
193
+ Output your items in a range of formats (:ruby, :json and :yaml currently)
194
+ Ruby is the default format and will automagically yielded from your source
195
+ </p>
196
+ <p>
197
+ Usage
198
+ </p>
199
+ <pre>output(:json)&#x000A;=&gt; &quot;[{title: \&quot;Ray\&quot;}, {title: \&quot;Peace\&quot;}]&quot;</pre>
200
+ </div>
201
+ <div class='source'>
202
+ <a class='source-toggle' href='#' onclick="toggleCode('M000021-source'); return false">
203
+ [show source]
204
+ </a>
205
+ <pre id='M000021-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 22</span>&#x000A;22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">output</span>(<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:ruby</span>)&#x000A;23: <span class="ruby-identifier">prepare!</span>&#x000A;24: <span class="ruby-identifier">dispatch</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:dispatch</span>&#x000A;25: <span class="ruby-identifier">output</span> = (<span class="ruby-ivar">@items</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-ivar">@items</span>&#x000A;26: &#x000A;27: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>&#x000A;28: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:json</span>&#x000A;29: <span class="ruby-keyword kw">return</span> <span class="ruby-operator">::</span><span class="ruby-constant">JSON</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-identifier">output</span>)&#x000A;30: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:yaml</span>&#x000A;31: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">output</span>)&#x000A;32: <span class="ruby-keyword kw">else</span>&#x000A;33: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span>&#x000A;34: <span class="ruby-keyword kw">end</span> &#x000A;35: <span class="ruby-keyword kw">end</span></pre>
206
+ </div>
207
+ </div>
208
+ <div class='public-instance method' id='method-M000022'>
209
+ <a name='M000022'> </a>
210
+ <div class='synopsis'>
211
+ <span class='name'>path</span>
212
+ <span class='arguments'>(*path)</span>
213
+ </div>
214
+ <div class='description'>
215
+ <p>
216
+ Path allows you to traverse the tree of a the items returned to only give
217
+ you access to what you&#8217;re interested in.
218
+ </p>
219
+ <p>
220
+ Usage: path :down, :to, :the, :data
221
+ </p>
222
+ <p>
223
+ Will traverse through a tree as follows:
224
+ </p>
225
+ <pre>{&#x000A; :down =&gt; {&#x000A; :to =&gt; {&#x000A; :the =&gt; {&#x000A; :data =&gt; []&#x000A; }&#x000A; }&#x000A; }&#x000A;}</pre>
226
+ <p>
227
+ You will need to help smoke find an array of items that you&#8217;re
228
+ interested in.
229
+ </p>
230
+ </div>
231
+ <div class='source'>
232
+ <a class='source-toggle' href='#' onclick="toggleCode('M000022-source'); return false">
233
+ [show source]
234
+ </a>
235
+ <pre id='M000022-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 62</span>&#x000A;62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">path</span>)&#x000A;63: <span class="ruby-ivar">@path</span> = <span class="ruby-identifier">path</span>&#x000A;64: <span class="ruby-keyword kw">end</span></pre>
236
+ </div>
237
+ </div>
238
+ <div class='public-instance method' id='method-M000024'>
239
+ <a name='M000024'> </a>
240
+ <div class='synopsis'>
241
+ <span class='name'>prepare</span>
242
+ <span class='arguments'>(&amp;block)</span>
243
+ </div>
244
+ <div class='description'>
245
+ <p>
246
+ Prepare is used when you&#8217;d like to provision for arguments /
247
+ variables to be set after the source definition. Eg, create a source
248
+ definition for twitter, omitting the &#8220;username&#8221;. Set the
249
+ username using chaining later.
250
+ </p>
251
+ <p>
252
+ Usage:
253
+ </p>
254
+ <pre># Definition&#x000A;Smoke.feed :twitter do&#x000A; prepare do&#x000A; url &quot;http://twitter.com/#{username}/rss&quot;&#x000A; end&#x000A;end&#x000A;&#x000A;# End use&#x000A;Smoke[:twitter].username(:benschwarz).output</pre>
255
+ </div>
256
+ <div class='source'>
257
+ <a class='source-toggle' href='#' onclick="toggleCode('M000024-source'); return false">
258
+ [show source]
259
+ </a>
260
+ <pre id='M000024-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 91</span>&#x000A;91: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prepare</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)&#x000A;92: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;requires a block&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>&#x000A;93: <span class="ruby-ivar">@prepare</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">block</span>&#x000A;94: <span class="ruby-keyword kw">end</span></pre>
261
+ </div>
262
+ </div>
263
+ <div class='public-instance method' id='method-M000029'>
264
+ <a name='M000029'> </a>
265
+ <div class='synopsis'>
266
+ <span class='name'>rename</span>
267
+ <span class='arguments'>(*args)</span>
268
+ </div>
269
+ <div class='description'>
270
+ <p>
271
+ Rename one or many keys at a time Suggested that you run it within an each
272
+ block, but it makes no difference other than readability
273
+ </p>
274
+ <p>
275
+ Usage
276
+ </p>
277
+ <pre># Renames all items with a key of href to link&#x000A;rename(:href =&gt; :link)</pre>
278
+ <p>
279
+ or
280
+ </p>
281
+ <pre>rename(:href =&gt; :link, :description =&gt; :excerpt)</pre>
282
+ </div>
283
+ <div class='source'>
284
+ <a class='source-toggle' href='#' onclick="toggleCode('M000029-source'); return false">
285
+ [show source]
286
+ </a>
287
+ <pre id='M000029-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 154</span>&#x000A;154: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rename</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)&#x000A;155: <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">rename</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) }&#x000A;156: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;157: <span class="ruby-keyword kw">end</span></pre>
288
+ </div>
289
+ </div>
290
+ <div class='public-instance method' id='method-M000026'>
291
+ <a name='M000026'> </a>
292
+ <div class='synopsis'>
293
+ <span class='name'>sort</span>
294
+ <span class='arguments'>(key)</span>
295
+ </div>
296
+ <div class='description'>
297
+ <p>
298
+ Re-sort items by a particular key
299
+ </p>
300
+ </div>
301
+ <div class='source'>
302
+ <a class='source-toggle' href='#' onclick="toggleCode('M000026-source'); return false">
303
+ [show source]
304
+ </a>
305
+ <pre id='M000026-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 109</span>&#x000A;109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort</span>(<span class="ruby-identifier">key</span>)&#x000A;110: <span class="ruby-ivar">@items</span> = <span class="ruby-ivar">@items</span>.<span class="ruby-identifier">sort_by</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>[<span class="ruby-identifier">key</span>] }&#x000A;111: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>&#x000A;112: <span class="ruby-constant">Smoke</span>.<span class="ruby-identifier">log</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;You're trying to sort by \&quot;#{key}\&quot; but it does not exist in your item set&quot;</span>&#x000A;113: <span class="ruby-keyword kw">ensure</span>&#x000A;114: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;115: <span class="ruby-keyword kw">end</span></pre>
306
+ </div>
307
+ </div>
308
+ <div class='public-instance method' id='method-M000030'>
309
+ <a name='M000030'> </a>
310
+ <div class='synopsis'>
311
+ <span class='name'>truncate</span>
312
+ <span class='arguments'>(length)</span>
313
+ </div>
314
+ <div class='description'>
315
+ <p>
316
+ Truncate your result set to this many objects
317
+ </p>
318
+ <p>
319
+ Usage
320
+ </p>
321
+ <pre>truncate(3).output&#x000A;=&gt; [{title =&gt; &quot;Canon&quot;}, {:title =&gt; &quot;Nikon&quot;}, {:title =&gt; &quot;Pentax&quot;}]</pre>
322
+ </div>
323
+ <div class='source'>
324
+ <a class='source-toggle' href='#' onclick="toggleCode('M000030-source'); return false">
325
+ [show source]
326
+ </a>
327
+ <pre id='M000030-source'> <span class="ruby-comment cmt"># File lib/smoke/origin.rb, line 165</span>&#x000A;165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">length</span>)&#x000A;166: <span class="ruby-ivar">@items</span> = <span class="ruby-ivar">@items</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)]&#x000A;167: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>&#x000A;168: <span class="ruby-keyword kw">end</span></pre>
328
+ </div>
329
+ </div>
330
+ </div>
331
+ </div>
332
+ </div>
333
+ </div>
334
+ <div id='footer-push'></div>
335
+ </div>
336
+ <div id='footer'>
337
+ <a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
338
+ </div>
339
+ </body>
340
+ </html>