Skip to content

Commit

Permalink
Merge pull request jamesmartin#166 from tagliala/chore/rubocop-space-…
Browse files Browse the repository at this point in the history
…offences

RuboCop Stage II: space offences
  • Loading branch information
jamesmartin authored Oct 8, 2024
2 parents cc0fc03 + fd57d94 commit 8b1f1cc
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 159 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.rubocop_todo.yml linguist-generated
120 changes: 0 additions & 120 deletions .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob("spec/**/*_spec.rb")
#t.rspec_opts = "--format documentation"
# t.rspec_opts = "--format documentation"
end
task :default => :spec
4 changes: 2 additions & 2 deletions lib/inline_svg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def add_custom_transformation(options)
if incompatible_transformation?(options.fetch(:transform))
raise InlineSvg::Configuration::Invalid.new("#{options.fetch(:transform)} should implement the .create_with_value and #transform methods")
end
@custom_transformations.merge!(Hash[ *[options.fetch(:attribute, :no_attribute), options] ])

@custom_transformations.merge!(Hash[*[options.fetch(:attribute, :no_attribute), options]])
end

def raise_on_file_not_found=(value)
Expand All @@ -81,7 +82,6 @@ def raise_on_file_not_found?
def incompatible_transformation?(klass)
!klass.is_a?(Class) || !klass.respond_to?(:create_with_value) || !klass.instance_methods.include?(:transform)
end

end

@configuration = InlineSvg::Configuration.new
Expand Down
8 changes: 4 additions & 4 deletions lib/inline_svg/action_view/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
module InlineSvg
module ActionView
module Helpers
def inline_svg_tag(filename, transform_params={})
def inline_svg_tag(filename, transform_params = {})
with_asset_finder(InlineSvg.configuration.asset_finder) do
render_inline_svg(filename, transform_params)
end
end

def inline_svg_pack_tag(filename, transform_params={})
def inline_svg_pack_tag(filename, transform_params = {})
with_asset_finder(InlineSvg::WebpackAssetFinder) do
render_inline_svg(filename, transform_params)
end
end

def inline_svg(filename, transform_params={})
def inline_svg(filename, transform_params = {})
render_inline_svg(filename, transform_params)
end

private

def render_inline_svg(filename, transform_params={})
def render_inline_svg(filename, transform_params = {})
begin
svg_file = read_svg(filename)
rescue InlineSvg::AssetFile::FileNotFound => error
Expand Down
1 change: 1 addition & 0 deletions lib/inline_svg/cached_asset_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def named(asset_name)
end

private

# Internal: Finds the key for a given asset name (using a Regex). In the
# event of an ambiguous asset_name matching multiple assets, this method
# ranks the matches by their full file path, choosing the shortest (most
Expand Down
12 changes: 6 additions & 6 deletions lib/inline_svg/transform_pipeline/transformations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def self.magnify_priorities(transforms)
transforms.inject({}) do |output, (name, definition)|
priority = definition.fetch(:priority, built_in_transformations.size)

output[name] = definition.merge( { priority: magnify(priority) } )
output[name] = definition.merge({ priority: magnify(priority) })
output
end
end

def self.magnify(priority=0)
def self.magnify(priority = 0)
(priority + 1) * built_in_transformations.size
end

Expand All @@ -59,15 +59,15 @@ def self.params_with_defaults(params)
end

def self.without_empty_values(params)
params.reject {|key, value| value.nil?}
params.reject { |key, value| value.nil? }
end

def self.all_default_values
custom_transformations
.values
.select {|opt| opt[:default_value] != nil}
.map {|opt| [opt[:attribute], opt[:default_value]]}
.inject({}) {|options, attrs| options.merge!(attrs[0] => attrs[1])}
.select { |opt| opt[:default_value] != nil }
.map { |opt| [opt[:attribute], opt[:default_value]] }
.inject({}) { |options, attrs| options.merge!(attrs[0] => attrs[1]) }
end

def self.no_transform
Expand Down
2 changes: 1 addition & 1 deletion lib/inline_svg/webpack_asset_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.find_asset(filename)
def initialize(filename)
@filename = filename
manifest_lookup = asset_helper.manifest.lookup(@filename)
@asset_path = manifest_lookup.present? ? URI(manifest_lookup).path : ""
@asset_path = manifest_lookup.present? ? URI(manifest_lookup).path : ""
end

def pathname
Expand Down
1 change: 1 addition & 0 deletions spec/cached_asset_file_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'pathname'
require_relative '../lib/inline_svg'

Expand Down
22 changes: 11 additions & 11 deletions spec/helpers/inline_svg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ def transform(doc)
end

describe InlineSvg::ActionView::Helpers do

let(:helper) { ( Class.new { include InlineSvg::ActionView::Helpers } ).new }
let(:helper) { (Class.new { include InlineSvg::ActionView::Helpers }).new }

shared_examples "inline_svg helper" do |helper_method:|

context "when passed the name of an SVG that does not exist" do
after(:each) do
InlineSvg.reset_configuration!
Expand Down Expand Up @@ -94,7 +92,6 @@ def transform(doc)
end

context "when passed an existing SVG file" do

context "and no options" do
it "returns a html safe version of the file's contents" do
example_file = '<svg xmlns="http://www.w3.org/2000/svg" xml:lang="en"><!-- This is a comment --></svg>'
Expand Down Expand Up @@ -151,7 +148,7 @@ def transform(doc)
context "with custom transformations" do
before(:each) do
InlineSvg.configure do |config|
config.add_custom_transformation({attribute: :custom, transform: WorkingCustomTransform})
config.add_custom_transformation({ attribute: :custom, transform: WorkingCustomTransform })
end
end

Expand All @@ -170,7 +167,7 @@ def transform(doc)
context "with custom transformations using a default value" do
before(:each) do
InlineSvg.configure do |config|
config.add_custom_transformation({attribute: :custom, transform: WorkingCustomTransform, default_value: 'default value'})
config.add_custom_transformation({ attribute: :custom, transform: WorkingCustomTransform, default_value: 'default value' })
end
end

Expand Down Expand Up @@ -198,27 +195,31 @@ def transform(doc)
end
end
end

end

context 'argument polimorphizm' do
let(:argument) { double('argument') }

it 'accept IO' do
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(true)
expect(InlineSvg::IOResource).to receive(:read).with(argument)
expect(InlineSvg::AssetFile).to_not receive(:named)
helper.send(helper_method, argument)
end

it 'accept filename' do
expect(InlineSvg::IOResource).to receive(:===).with(argument).and_return(false)
expect(InlineSvg::IOResource).to_not receive(:read)
expect(InlineSvg::AssetFile).to receive(:named).with(argument)
helper.send(helper_method, argument)
end
end

context 'when passed IO object argument' do
let(:io_object) { double('io_object') }
let(:file_path) { File.expand_path('../../files/example.svg', __FILE__) }
let(:answer) { File.read(file_path) }

it 'return valid svg' do
expect(InlineSvg::IOResource).to receive(:===).with(io_object).and_return(true)
expect(InlineSvg::IOResource).to receive(:read).with(io_object).and_return("<svg><!-- Test IO --></svg>")
Expand All @@ -232,15 +233,14 @@ def transform(doc)
expect(output).to eq "<svg xmlns=\"http://www.w3.org/2000/svg\" xml:lang=\"en\" role=\"presentation\"><!-- This is a test comment --></svg>"
expect(output).to be_html_safe
end

end

context 'default output' do
it "returns an SVG tag without any pre or post whitespace characters" do
input_svg = '<svg></svg>'

allow(InlineSvg::AssetFile).to receive(:named).with('some-file').and_return(input_svg)

expect(helper.send(helper_method, 'some-file')).to eq "<svg></svg>"
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/inline_svg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def self.named(filename); end
config.add_custom_transformation(attribute: :my_transform, transform: MyCustomTransform)
end

expect(InlineSvg.configuration.custom_transformations).to eq({my_transform: {attribute: :my_transform, transform: MyCustomTransform}})
expect(InlineSvg.configuration.custom_transformations).to eq({ my_transform: { attribute: :my_transform, transform: MyCustomTransform } })
end

it "rejects transformations that do not implement .create_with_value" do
Expand All @@ -122,7 +122,6 @@ def self.named(filename); end
end
end.to raise_error(InlineSvg::Configuration::Invalid, /#{:not_a_class} should implement the .create_with_value and #transform methods/)
end

end
end
end
Loading

0 comments on commit 8b1f1cc

Please sign in to comment.