From e61799ba812bd4c7d0e31c18fd0a597a5286b12f Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 2 Oct 2020 18:12:51 +0200 Subject: [PATCH] =?UTF-8?q?Appease=20the=20RuboCop=20=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Nicolò Rebughini --- .rubocop.yml | 14 ++++++++++ lib/solidus_feeds/feed.rb | 20 ++++++++------ lib/solidus_feeds/feeds.rb | 26 +++++++++++-------- .../generators/google_merchant.rb | 2 +- .../{ => generators}/google_merchant_spec.rb | 0 spec/solidus_feeds/feeds_spec.rb | 17 ++++++------ 6 files changed, 50 insertions(+), 29 deletions(-) rename spec/lib/solidus_feeds/{ => generators}/google_merchant_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index 6207a64..8eca987 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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 diff --git a/lib/solidus_feeds/feed.rb b/lib/solidus_feeds/feed.rb index 0385090..9740966 100644 --- a/lib/solidus_feeds/feed.rb +++ b/lib/solidus_feeds/feed.rb @@ -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 diff --git a/lib/solidus_feeds/feeds.rb b/lib/solidus_feeds/feeds.rb index e726d2a..d16efa7 100644 --- a/lib/solidus_feeds/feeds.rb +++ b/lib/solidus_feeds/feeds.rb @@ -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 diff --git a/lib/solidus_feeds/generators/google_merchant.rb b/lib/solidus_feeds/generators/google_merchant.rb index 3d7d82d..c1c94bf 100644 --- a/lib/solidus_feeds/generators/google_merchant.rb +++ b/lib/solidus_feeds/generators/google_merchant.rb @@ -1,4 +1,4 @@ -# lib/google_merchant.rb +# frozen_string_literal: true require 'builder' diff --git a/spec/lib/solidus_feeds/google_merchant_spec.rb b/spec/lib/solidus_feeds/generators/google_merchant_spec.rb similarity index 100% rename from spec/lib/solidus_feeds/google_merchant_spec.rb rename to spec/lib/solidus_feeds/generators/google_merchant_spec.rb diff --git a/spec/solidus_feeds/feeds_spec.rb b/spec/solidus_feeds/feeds_spec.rb index f2efda5..ee23db1 100644 --- a/spec/solidus_feeds/feeds_spec.rb +++ b/spec/solidus_feeds/feeds_spec.rb @@ -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