benschwarz-smoke 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +14 -2
- data/VERSION.yml +2 -2
- data/lib/smoke.rb +8 -14
- data/lib/smoke/origin.rb +3 -2
- data/lib/smoke/source/join.rb +34 -0
- data/spec/smoke/source/join_spec.rb +66 -0
- data/spec/smoke_spec.rb +1 -28
- metadata +4 -2
data/README.markdown
CHANGED
@@ -48,7 +48,21 @@ or even
|
|
48
48
|
rename :shit_name => :title
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
### Define a source allowing for variables to be injected later
|
51
53
|
|
54
|
+
Source definition:
|
55
|
+
|
56
|
+
Smoke.feed :delicious do
|
57
|
+
prepare do
|
58
|
+
url "http://feeds.delicious.com/v2/rss/#{username}?count=15"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Execution:
|
63
|
+
|
64
|
+
Smoke[:delicious].username("bschwarz").output
|
65
|
+
|
52
66
|
### CI
|
53
67
|
|
54
68
|
Integrity [is running for smoke](http://integrity.ffolio.net/smoke)
|
@@ -56,8 +70,6 @@ Integrity [is running for smoke](http://integrity.ffolio.net/smoke)
|
|
56
70
|
|
57
71
|
### TODO (working on, just mental notes)
|
58
72
|
|
59
|
-
* Joined sources require a call to dispatch when their parent calls output
|
60
|
-
* Sources that are renamed also need their @name's renaming
|
61
73
|
* Implement a disaptch / request method that will actually thread property (event-machine)
|
62
74
|
* Checkout experimental fakeweb version to stub out the yql specs
|
63
75
|
|
data/VERSION.yml
CHANGED
data/lib/smoke.rb
CHANGED
@@ -27,16 +27,6 @@ module Smoke
|
|
27
27
|
active_sources[source]
|
28
28
|
end
|
29
29
|
|
30
|
-
def join(*sources, &block)
|
31
|
-
@items = get_sources(sources).map {|source| source[1].items }.flatten
|
32
|
-
|
33
|
-
joined_name = (sources << "joined").join("_").to_sym
|
34
|
-
source = Origin.new(joined_name, &block)
|
35
|
-
|
36
|
-
source.items = @items
|
37
|
-
return source
|
38
|
-
end
|
39
|
-
|
40
30
|
# Activates new instances of sources
|
41
31
|
# Source instances are stored within the
|
42
32
|
# @@active_sources class variable for later use
|
@@ -55,6 +45,7 @@ module Smoke
|
|
55
45
|
# Rename a source
|
56
46
|
def rename(candidates)
|
57
47
|
candidates.each do |o, n|
|
48
|
+
active_sources[o].name = n.to_s
|
58
49
|
active_sources.rename(o => n)
|
59
50
|
return active_sources[n]
|
60
51
|
end
|
@@ -74,10 +65,13 @@ module Smoke
|
|
74
65
|
def data(name, &block); Smoke::Source::Data.new(name, &block); end
|
75
66
|
def feed(name, &block); Smoke::Source::Feed.new(name, &block); end
|
76
67
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
68
|
+
# Join multiple sources together into a single feed
|
69
|
+
# Usage:
|
70
|
+
# Smoke.join(:delicious, :twitter, :flickr) do
|
71
|
+
# name :stream
|
72
|
+
# path :photos, :photo
|
73
|
+
# end
|
74
|
+
def join(*names, &block); Smoke::Source::Join.new(names, &block); end
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
data/lib/smoke/origin.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Smoke
|
2
2
|
class Origin
|
3
|
-
attr_reader :items
|
3
|
+
attr_reader :items
|
4
|
+
attr_accessor :name
|
4
5
|
|
5
6
|
def initialize(name, &block)
|
6
7
|
raise StandardError, "Sources must have a name" unless name
|
@@ -182,7 +183,7 @@ module Smoke
|
|
182
183
|
end
|
183
184
|
|
184
185
|
def activate!
|
185
|
-
Smoke.activate(name, self)
|
186
|
+
Smoke.activate(@name, self)
|
186
187
|
end
|
187
188
|
end
|
188
189
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Smoke
|
2
|
+
module Source # :nodoc:
|
3
|
+
# The "Joiner" source is a special source
|
4
|
+
# that can be used to join multiple sources together
|
5
|
+
# and proxy call dispatch for each source
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
# Smoke.join(:delicious, :twitter, :flickr) do
|
9
|
+
# name :stream
|
10
|
+
# path :photos, :photo
|
11
|
+
# end
|
12
|
+
class Join < Origin # :nodoc:
|
13
|
+
def initialize(names, &block)
|
14
|
+
@names = names
|
15
|
+
super((names << "joined").join("_").to_sym, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def sources
|
20
|
+
Smoke.active_sources.find_all{|k, v| @names.include?(k) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def dispatch
|
24
|
+
# Recall dispatch
|
25
|
+
sources.each do |source|
|
26
|
+
source.last.send(:dispatch) if source.last.respond_to?(:dispatch)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Re-map items
|
30
|
+
@items = sources.map {|source| source.last.items }.flatten
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "..", "spec_helper.rb")
|
2
|
+
|
3
|
+
describe "Join" do
|
4
|
+
before :all do
|
5
|
+
@source_a = TestSource.source :a
|
6
|
+
@source_b = TestSource.source :b
|
7
|
+
@source_c = TestSource.source :c
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "joining" do
|
11
|
+
before do
|
12
|
+
@joined = Smoke.join(:a, :b)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be named in a_b_joined" do
|
16
|
+
Smoke[:a_b_joined].should be_an_instance_of(Smoke::Source::Join)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should contain items from sources a and b" do
|
20
|
+
Smoke[:a_b_joined].output.size.should == (@source_a.output.size + @source_b.output.size)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept a block" do
|
24
|
+
lambda { Smoke.join(:a, :b, :c, Proc.new {}) }.should_not raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow sorting" do
|
28
|
+
Smoke[:a_b_joined].should respond_to(:sort)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should allow changes to output" do
|
32
|
+
Smoke[:a_b_joined].should respond_to(:output)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "renaming" do
|
36
|
+
it "should allow renaming" do
|
37
|
+
Smoke[:a_b_joined].should respond_to(:rename)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be renamed" do
|
41
|
+
Smoke.rename(:a_b_joined => :rename_spec)
|
42
|
+
Smoke[:rename_spec].should be_an_instance_of(Smoke::Source::Join)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should change its name property after being renamed" do
|
46
|
+
Smoke[:rename_spec].name.should == "rename_spec"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "dispatching" do
|
51
|
+
before :all do
|
52
|
+
FakeWeb.register_uri("http://photos.tld", :response => File.join(SPEC_DIR, 'supports', 'flickr-photo.json'))
|
53
|
+
|
54
|
+
Smoke.data(:should_dispatch) do
|
55
|
+
url "http://photos.tld"
|
56
|
+
path :photos, :photo
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should call dispatch for its children" do
|
61
|
+
Smoke[:should_dispatch].should_receive(:dispatch)
|
62
|
+
Smoke.join(:a, :should_dispatch).output
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/smoke_spec.rb
CHANGED
@@ -1,36 +1,9 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
2
2
|
|
3
3
|
describe Smoke do
|
4
|
-
before do
|
4
|
+
before :all do
|
5
5
|
@source_a = TestSource.source :a
|
6
6
|
@source_b = TestSource.source :b
|
7
|
-
@source_c = TestSource.source :c
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "joining" do
|
11
|
-
before do
|
12
|
-
@joined = Smoke.join(:a, :b)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should contain items from sources a and b" do
|
16
|
-
@joined.output.size.should == (@source_a.output.size + @source_b.output.size)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should accept a block" do
|
20
|
-
lambda { Smoke.join(:a, :b, Proc.new {}) }.should_not raise_error
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should allow sorting" do
|
24
|
-
Smoke.join(:a, :b).should respond_to(:sort)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow renaming" do
|
28
|
-
Smoke.join(:a, :b).should respond_to(:rename)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should allow changes to output" do
|
32
|
-
Smoke.join(:a, :b).should respond_to(:output)
|
33
|
-
end
|
34
7
|
end
|
35
8
|
|
36
9
|
describe "active sources" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: benschwarz-smoke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Schwarz
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/smoke/source
|
53
53
|
- lib/smoke/source/data.rb
|
54
54
|
- lib/smoke/source/feed.rb
|
55
|
+
- lib/smoke/source/join.rb
|
55
56
|
- lib/smoke/source/yql.rb
|
56
57
|
- lib/smoke.rb
|
57
58
|
- spec/core_ext
|
@@ -62,6 +63,7 @@ files:
|
|
62
63
|
- spec/smoke/source
|
63
64
|
- spec/smoke/source/data_spec.rb
|
64
65
|
- spec/smoke/source/feed_spec.rb
|
66
|
+
- spec/smoke/source/join_spec.rb
|
65
67
|
- spec/smoke/source/yql_spec.rb
|
66
68
|
- spec/smoke_spec.rb
|
67
69
|
- spec/spec.opts
|
@@ -98,7 +100,7 @@ requirements: []
|
|
98
100
|
rubyforge_project:
|
99
101
|
rubygems_version: 1.2.0
|
100
102
|
signing_key:
|
101
|
-
specification_version:
|
103
|
+
specification_version: 2
|
102
104
|
summary: smoke is a DSL that allows you to take data from YQL, RSS / Atom
|
103
105
|
test_files: []
|
104
106
|
|