Skip to content

Commit

Permalink
Appease the RuboCop 🤖
Browse files Browse the repository at this point in the history
Co-Authored-By: Nicolò Rebughini <[email protected]>
  • Loading branch information
elia and nirebu committed Oct 9, 2020
1 parent 51dcd6e commit e61799b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
require:
- solidus_dev_support/rubocop

AllCops:
NewCops: enable

RSpec/MultipleExpectations:
Enabled: false

Layout/LineLength:
Exclude:
- spec/lib/solidus_feeds/generators/google_merchant_spec.rb

# Waiting for https://github.com/rubocop-hq/rubocop/pull/8874 to be merged
Style/RedundantBegin:
Enabled: false
20 changes: 12 additions & 8 deletions lib/solidus_feeds/feed.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
class SolidusFeeds::Feed
attr_accessor :generator, :publisher
# frozen_string_literal: true

def generate(output)
generator.call(output)
end
module SolidusFeeds
class Feed
attr_accessor :generator, :publisher

def generate(output)
generator.call(output)
end

def publish
publisher.call do |output|
generate(output)
def publish
publisher.call do |output|
generate(output)
end
end
end
end
26 changes: 15 additions & 11 deletions lib/solidus_feeds/feeds.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module SolidusFeeds::Feeds
def feeds
@feeds ||= {}
end
# frozen_string_literal: true

def register name, &block
feeds[name] = block
end
module SolidusFeeds
module Feeds
def feeds
@feeds ||= {}
end

def find(name)
SolidusFeeds::Feed.new.tap { |feed| feeds[name].call(feed) }
end
def register(name, &block)
feeds[name] = block
end

SolidusFeeds.extend self
def find(name)
SolidusFeeds::Feed.new.tap { |feed| feeds[name].call(feed) }
end

SolidusFeeds.extend self
end
end
2 changes: 1 addition & 1 deletion lib/solidus_feeds/generators/google_merchant.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# lib/google_merchant.rb
# frozen_string_literal: true

require 'builder'

Expand Down
17 changes: 8 additions & 9 deletions spec/solidus_feeds/feeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
require 'csv'

RSpec.describe SolidusFeeds::Feeds do
subject(:solidus_feeds) do
Class.new.tap { |klass| klass.extend described_class }
end
subject(:solidus_feeds) { Class.new.tap { |klass| klass.extend described_class } }

let(:io) { StringIO.new }
let(:publisher) { -> &block { block.call(io) } }
let(:publisher) { ->(&block) { block.call(io) } }
let(:generator) {
-> io {
csv = CSV.new(io)
csv << ["some", "data"]
csv << ["another", "line"]
}
->(io) {
csv = CSV.new(io)
csv << ["some", "data"]
csv << ["another", "line"]
}
}

it 'allows to register, generate, and publish feeds' do
Expand Down

0 comments on commit e61799b

Please sign in to comment.