Skip to content

Commit

Permalink
Make CarrierWave::MiniMagick#mini_magic_image private
Browse files Browse the repository at this point in the history
This method doesn't need to be part of the public API. It's used by
the new public `#width` and `#height` methods (introduced by carrierwaveuploader#1405).

This commit also fixes a typo in the method name and tweaks the comments.
  • Loading branch information
Mehdi Lahmam authored and Kevin Mehlbrech committed Aug 9, 2016
1 parent d9fdccd commit 10eb21b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
33 changes: 14 additions & 19 deletions lib/carrierwave/processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,40 +245,25 @@ def resize_and_pad(width, height, background=:transparent, gravity='Center', com
end

##
# Return the mini magic instance of the image
#
# === Returns
#
# #<MiniMagick::Image>
#
def mini_magic_image
if url
::MiniMagick::Image.open(url)
else
::MiniMagick::Image.open(current_path)
end
end

##
# Gives the width of the image, useful for model validation
# Returns the width of the image in pixels.
#
# === Returns
#
# [Integer] the image's width in pixels
#
def width
mini_magic_image[:width]
mini_magick_image[:width]
end

##
# Gives the height of the image, useful for model validation
# Returns the height of the image in pixels.
#
# === Returns
#
# [Integer] the image's height in pixels
#
def height
mini_magic_image[:height]
mini_magick_image[:height]
end

##
Expand Down Expand Up @@ -338,5 +323,15 @@ def append_combine_options(cmd, combine_options)
end
end

private

def mini_magick_image
if url
::MiniMagick::Image.open(url)
else
::MiniMagick::Image.open(current_path)
end
end

end # MiniMagick
end # CarrierWave
16 changes: 8 additions & 8 deletions spec/processing/mini_magick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
end
end

describe "#width and #height" do
it "should return the width and height of the image" do
@instance.resize_to_fill(200, 300)
expect(@instance.width).to eq(200)
expect(@instance.height).to eq(300)
end
end

describe "test errors" do
context "invalid image file" do
before do
Expand Down Expand Up @@ -188,12 +196,4 @@
end
end

describe "return_width_and_height" do
it "should return the width and height of the image" do
@instance.resize_to_fill(200, 300)
expect(@instance.width).to eq(200)
expect(@instance.height).to eq(300)
end
end

end

0 comments on commit 10eb21b

Please sign in to comment.