-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nebulab/elia/innitial-registry
Initial feed registry implementation
- Loading branch information
Showing
5 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class SolidusFeeds::Feed | ||
attr_accessor :generator, :publisher | ||
|
||
def generate(output) | ||
generator.call(output) | ||
end | ||
|
||
def publish | ||
publisher.call do |output| | ||
generate(output) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module SolidusFeeds::Feeds | ||
def feeds | ||
@feeds ||= {} | ||
end | ||
|
||
def register name, &block | ||
feeds[name] = block | ||
end | ||
|
||
def find(name) | ||
SolidusFeeds::Feed.new.tap { |feed| feeds[name].call(feed) } | ||
end | ||
|
||
SolidusFeeds.extend self | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
require 'stringio' | ||
require 'csv' | ||
|
||
RSpec.describe SolidusFeeds::Feeds do | ||
subject(:solidus_feeds) do | ||
Class.new.tap { |klass| klass.extend described_class } | ||
end | ||
let(:io) { StringIO.new } | ||
let(:publisher) { -> &block { block.call(io) } } | ||
let(:generator) { | ||
-> io { | ||
csv = CSV.new(io) | ||
csv << ["some", "data"] | ||
csv << ["another", "line"] | ||
} | ||
} | ||
|
||
it 'allows to register, generate, and publish feeds' do | ||
solidus_feeds.register :foo do |feed| | ||
feed.publisher = publisher | ||
feed.generator = generator | ||
end | ||
|
||
feed = solidus_feeds.find(:foo) | ||
expect(feed).to be_a SolidusFeeds::Feed | ||
|
||
feed.publish | ||
expect(io.string).to eq("some,data\nanother,line\n") | ||
end | ||
end |