smoke 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -4,7 +4,7 @@ smoke is a Ruby based DSL that allows you to query web services such as YQL, RSS
4
4
 
5
5
  These "services" can then be re-represented, sorted and filtered. Data can be collected from multiple sources, sorted via a common property, chopped up and refried.
6
6
 
7
- Then you can output as a plain ruby object (or JSON)
7
+ Then you can output as a plain ruby object or one of your other favourites (JSON, YAML, XML)
8
8
 
9
9
  ## Examples of use
10
10
 
data/Rakefile CHANGED
@@ -12,11 +12,12 @@ begin
12
12
  gem.authors = ["Ben Schwarz"]
13
13
  gem.files = FileList['lib/**/*.rb', 'rdoc/**/*', '[A-Z]*', 'spec/**/*', 'vendor/**/*'].to_a
14
14
  gem.add_dependency("simple-rss", "1.2")
15
- gem.add_dependency("json", "1.1.3")
15
+ gem.add_dependency("json", ">= 1.1.3")
16
16
  gem.add_dependency("fakeweb", "1.2.5")
17
- gem.add_dependency("crack", "0.1.1")
17
+ gem.add_dependency("crack", ">= 0.1.1")
18
18
  gem.add_dependency("moneta", "0.6.0")
19
19
  gem.add_dependency("rest-client", "1.0.3")
20
+ gem.add_dependency("nokogiri", "1.3.2")
20
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
22
  end
22
23
  rescue LoadError
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 11
2
+ :patch: 12
3
3
  :major: 0
4
4
  :minor: 5
data/lib/smoke.rb CHANGED
@@ -6,6 +6,7 @@ require 'json'
6
6
  require 'crack'
7
7
  require 'moneta'
8
8
  require 'restclient'
9
+ require 'nokogiri'
9
10
 
10
11
  module Smoke
11
12
  class << self
@@ -103,7 +104,7 @@ module Smoke
103
104
  end
104
105
  end
105
106
 
106
- %w(core_ext/hash core_ext/string smoke/cache smoke/request smoke/origin).each {|r| require File.join(File.dirname(__FILE__), r)}
107
+ %w(core_ext/hash core_ext/string smoke/cache smoke/request smoke/origin smoke/output/xml).each {|r| require File.join(File.dirname(__FILE__), r)}
107
108
 
108
109
  class Object # :nodoc:
109
110
  include Smoke
data/lib/smoke/cache.rb CHANGED
@@ -17,6 +17,11 @@ module Smoke
17
17
  def enabled?
18
18
  Smoke.config[:cache][:enabled]
19
19
  end
20
+
21
+ # Clear all your request caches
22
+ def clear!
23
+ cache.clear
24
+ end
20
25
 
21
26
  protected
22
27
  def cache
data/lib/smoke/origin.rb CHANGED
@@ -28,9 +28,11 @@ module Smoke
28
28
  return ::JSON.generate(@items)
29
29
  when :yaml
30
30
  return YAML.dump(@items)
31
+ when :xml
32
+ return Smoke::Output::XML.generate(@name, @items)
31
33
  else
32
34
  return @items
33
- end
35
+ end
34
36
  end
35
37
 
36
38
  def items=(response) # :nodoc:
@@ -225,7 +227,7 @@ module Smoke
225
227
 
226
228
  private
227
229
  def prepare!
228
- @prepare.each{|p| p.call } unless @prepare.nil?
230
+ @prepare.each{|block| block.call} unless @prepare.empty?
229
231
  end
230
232
 
231
233
  def transform!
@@ -0,0 +1,23 @@
1
+ module Smoke
2
+ module Output
3
+ class XML
4
+ def self.generate(tree_name, items)
5
+ builder = Nokogiri::XML::Builder.new do |xml|
6
+ xml.send(tree_name) {
7
+ xml.items {
8
+ items.each do |item|
9
+ xml.item {
10
+ item.each_pair do |key, value|
11
+ xml.send(key, value)
12
+ end
13
+ }
14
+ end
15
+ }
16
+ }
17
+ end
18
+
19
+ builder.to_xml
20
+ end
21
+ end
22
+ end
23
+ end
@@ -29,7 +29,7 @@ module Smoke
29
29
 
30
30
  unless args.empty?
31
31
  sources.each do |source|
32
- source.last.instance_variable_set(ivar, args.pop)
32
+ source.last.instance_variable_set(ivar, args.last)
33
33
  end
34
34
  end
35
35
 
@@ -6,9 +6,13 @@ describe Smoke::Cache do
6
6
  Smoke::Cache.should respond_to(:fetch)
7
7
  end
8
8
 
9
- it "should responsd to enabled?" do
9
+ it "should respond to enabled?" do
10
10
  Smoke::Cache.should respond_to(:enabled?)
11
11
  end
12
+
13
+ it "should respond to clear!" do
14
+ Smoke::Cache.should respond_to(:clear!)
15
+ end
12
16
  end
13
17
 
14
18
  describe "configuration" do
@@ -41,7 +45,7 @@ describe Smoke::Cache do
41
45
  end
42
46
  end
43
47
 
44
- describe "caching my block" do
48
+ describe "caching my request" do
45
49
  before :all do
46
50
  Smoke.configure do |c|
47
51
  c[:cache][:enabled] = true
@@ -71,5 +75,10 @@ describe Smoke::Cache do
71
75
  Smoke::Cache.fetch @url, {}
72
76
  @store['33af9f13054e64520430f7a437cdd377'].should_not be_nil
73
77
  end
78
+
79
+ it "should be cleared" do
80
+ Smoke::Cache.clear!
81
+ @store['33af9f13054e64520430f7a437cdd377'].should be_nil
82
+ end
74
83
  end
75
84
  end
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
2
+
3
+ describe Smoke::Output::XML do
4
+ before do
5
+ @tree = "tree"
6
+ @items = [{:animal => "monkey"}]
7
+ @xml = Smoke::Output::XML.generate(@tree, @items)
8
+ @document = Nokogiri::XML(@xml)
9
+ end
10
+
11
+ it "should respond to generate" do
12
+ Smoke::Output::XML.should respond_to(:generate)
13
+ end
14
+
15
+ it "should start the tree off with a named key" do
16
+ @document.css("tree").should_not be_nil
17
+ end
18
+
19
+ it "should contain items" do
20
+ @document.css("items").each do |item|
21
+ item.content.should =~ /monkey/
22
+ end
23
+ end
24
+ end
@@ -18,6 +18,7 @@ describe "Join" do
18
18
 
19
19
  it "should contain items from sources a and b" do
20
20
  Smoke[:a_b_joined].output.size.should == (@source_a.output.size + @source_b.output.size)
21
+ Smoke[:a_b_joined].output.first.should == @source_a.output.first
21
22
  end
22
23
 
23
24
  it "should accept a block" do
@@ -88,6 +89,7 @@ describe "Join" do
88
89
  it "should inject variables to its source items" do
89
90
  Smoke.variable_injection_joined.some_ivar("value")
90
91
  Smoke.variable.some_ivar.should == "value"
92
+ Smoke.injection.some_ivar.should == "value"
91
93
  end
92
94
  end
93
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smoke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Schwarz
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-18 00:00:00 +10:00
12
+ date: 2009-09-27 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -28,7 +28,7 @@ dependencies:
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "="
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.3
34
34
  version:
@@ -48,7 +48,7 @@ dependencies:
48
48
  version_requirement:
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "="
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: 0.1.1
54
54
  version:
@@ -72,6 +72,16 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: 1.0.3
74
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: nokogiri
77
+ type: :runtime
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "="
82
+ - !ruby/object:Gem::Version
83
+ version: 1.3.2
84
+ version:
75
85
  description:
76
86
  email: ben.schwarz@gmail.com
77
87
  executables: []
@@ -91,6 +101,7 @@ files:
91
101
  - lib/smoke.rb
92
102
  - lib/smoke/cache.rb
93
103
  - lib/smoke/origin.rb
104
+ - lib/smoke/output/xml.rb
94
105
  - lib/smoke/request.rb
95
106
  - lib/smoke/source/data.rb
96
107
  - lib/smoke/source/feed.rb
@@ -119,6 +130,7 @@ files:
119
130
  - spec/core_ext/hash_spec.rb
120
131
  - spec/smoke/cache_spec.rb
121
132
  - spec/smoke/origin_spec.rb
133
+ - spec/smoke/output/xml_spec.rb
122
134
  - spec/smoke/request_spec.rb
123
135
  - spec/smoke/shared_spec.rb
124
136
  - spec/smoke/source/data_spec.rb
@@ -160,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
172
  requirements: []
161
173
 
162
174
  rubyforge_project:
163
- rubygems_version: 1.3.2
175
+ rubygems_version: 1.3.5
164
176
  signing_key:
165
177
  specification_version: 3
166
178
  summary: smoke is a Ruby based DSL that allows you to query web services such as YQL, RSS / Atom and JSON or XML in an elegant manner.
@@ -168,6 +180,7 @@ test_files:
168
180
  - spec/core_ext/hash_spec.rb
169
181
  - spec/smoke/cache_spec.rb
170
182
  - spec/smoke/origin_spec.rb
183
+ - spec/smoke/output/xml_spec.rb
171
184
  - spec/smoke/request_spec.rb
172
185
  - spec/smoke/shared_spec.rb
173
186
  - spec/smoke/source/data_spec.rb