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
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
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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
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
|
-
|
24
|
+
protected
|
31
25
|
def cache
|
32
|
-
Moneta.
|
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
|
36
|
-
|
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
|
28
|
-
|
29
|
-
|
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, &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>
 6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
 7: <span class="ruby-identifier">raise</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-value str">"Sources must have a name"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">name</span>
 8: <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">name</span>
 9: <span class="ruby-ivar">@items</span>, <span class="ruby-ivar">@prepare</span>, <span class="ruby-ivar">@transformation</span> = [], [], []
10: 
11: <span class="ruby-identifier">activate!</span>
12: <span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
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
 ...
 discard(:title, /tuesday/i)
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>
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>)
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> }
142: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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'>(&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
 rename(:href => :link)
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>
72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">emit</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
73: <span class="ruby-ivar">@transformation</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
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
 ...
 keep(:title, /tuesday/i)
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>
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>)
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> }
128: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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, &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>
 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">&</span><span class="ruby-identifier">block</span>)
 97: <span class="ruby-identifier">ivar</span> = <span class="ruby-node">"@#{symbol}"</span>
 98: 
 99: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
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> 
101: <span class="ruby-keyword kw">else</span>
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>)
103: <span class="ruby-keyword kw">end</span>
104: 
105: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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)
=> "[{title: \"Ray\"}, {title: \"Peace\"}]"</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>
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>)
23: <span class="ruby-identifier">prepare!</span>
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>
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>
26: 
27: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">type</span>
28: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:json</span>
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>)
30: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:yaml</span>
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>)
32: <span class="ruby-keyword kw">else</span>
33: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span>
34: <span class="ruby-keyword kw">end</span> 
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’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>{
 :down => {
 :to => {
 :the => {
 :data => []
 }
 }
 }
}</pre>
|
226
|
+
<p>
|
227
|
+
You will need to help smoke find an array of items that you’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>
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>)
63: <span class="ruby-ivar">@path</span> = <span class="ruby-identifier">path</span>
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'>(&block)</span>
|
243
|
+
</div>
|
244
|
+
<div class='description'>
|
245
|
+
<p>
|
246
|
+
Prepare is used when you’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 “username”. Set the
|
249
|
+
username using chaining later.
|
250
|
+
</p>
|
251
|
+
<p>
|
252
|
+
Usage:
|
253
|
+
</p>
|
254
|
+
<pre># Definition
Smoke.feed :twitter do
 prepare do
 url "http://twitter.com/#{username}/rss"
 end
end

# End use
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>
91: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prepare</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
92: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"requires a block"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">block_given?</span>
93: <span class="ruby-ivar">@prepare</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">block</span>
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
rename(:href => :link)</pre>
|
278
|
+
<p>
|
279
|
+
or
|
280
|
+
</p>
|
281
|
+
<pre>rename(:href => :link, :description => :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>
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>)
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>) }
156: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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>
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort</span>(<span class="ruby-identifier">key</span>)
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>] }
111: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NoMethodError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
112: <span class="ruby-constant">Smoke</span>.<span class="ruby-identifier">log</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">"You're trying to sort by \"#{key}\" but it does not exist in your item set"</span>
113: <span class="ruby-keyword kw">ensure</span>
114: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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
=> [{title => "Canon"}, {:title => "Nikon"}, {:title => "Pentax"}]</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>
165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">length</span>)
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>)]
167: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
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>
|