Skip to content

Commit

Permalink
Merge pull request jamesmartin#167 from tagliala/chore/rubocop-safe-p…
Browse files Browse the repository at this point in the history
…erformance-offences

RuboCop Stage III: Fix safe performance offenses
  • Loading branch information
jamesmartin authored Oct 9, 2024
2 parents 8b1f1cc + 4c85530 commit 10f0749
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 33 deletions.
28 changes: 1 addition & 27 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 lib/inline_svg/cached_asset_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(paths: [], filters: [])
@paths = Array(paths).compact.map { |p| Pathname.new(p) }
@filters = Array(filters).map { |f| Regexp.new(f) }
@assets = @paths.reduce({}) { |assets, p| assets.merge(read_assets(assets, p)) }
@sorted_asset_keys = assets.keys.sort { |a, b| a.size <=> b.size }
@sorted_asset_keys = assets.keys.sort_by(&:size)
end

# Public: Finds the named asset and returns the contents as a string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def with_valid_hash_from(hash)
end

def dasherize(string)
string.to_s.gsub(/_/, "-")
string.to_s.tr('_', "-")
end
end
end
4 changes: 2 additions & 2 deletions lib/inline_svg/transform_pipeline/transformations/size.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def transform(doc)
end

def width_of(value)
value.split(/\*/).map(&:strip)[0]
value.split("*").map(&:strip)[0]
end

def height_of(value)
value.split(/\*/).map(&:strip)[1] || width_of(value)
value.split("*").map(&:strip)[1] || width_of(value)
end
end
end
4 changes: 2 additions & 2 deletions spec/inline_svg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def self.named(filename); end
InlineSvg.configure do |config|
config.add_custom_transformation(attribute: :irrelevant, transform: MyInvalidCustomTransformKlass)
end
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformKlass} should implement the .create_with_value and #transform methods/)
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformKlass} should implement the .create_with_value and #transform methods/o)
end

it "rejects transformations that does not implement #transform" do
expect do
InlineSvg.configure do |config|
config.add_custom_transformation(attribute: :irrelevant, transform: MyInvalidCustomTransformInstance)
end
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformInstance} should implement the .create_with_value and #transform methods/)
end.to raise_error(InlineSvg::Configuration::Invalid, /#{MyInvalidCustomTransformInstance} should implement the .create_with_value and #transform methods/o)
end

it "rejects transformations that are not classes" do
Expand Down

0 comments on commit 10f0749

Please sign in to comment.