mojo_magick 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require_relative "test_helper"
2
2
 
3
3
  class MojoMagickOptBuilderTest < MiniTest::Test
4
4
  # These tests make the assumption that if we call #raw_command with the
@@ -10,36 +10,36 @@ class MojoMagickOptBuilderTest < MiniTest::Test
10
10
  end
11
11
 
12
12
  def test_annotate
13
- @builder.annotate 'blah'
14
- assert_equal '-annotate 0 blah', @builder.to_s
13
+ @builder.annotate "blah"
14
+ assert_equal %w[-annotate 0 blah], @builder.to_a
15
15
  end
16
16
 
17
17
  def test_annotate_with_escapeable_string
18
- @builder.annotate 'it\'s'
19
- assert_equal '-annotate 0 "it\'s"', @builder.to_s
18
+ @builder.annotate "it's"
19
+ assert_equal %w[-annotate 0 it's], @builder.to_a
20
20
  end
21
21
 
22
22
  def test_annotate_with_full_args
23
- @builder.annotate '5 it\'s'
24
- assert_equal '-annotate 5 "it\'s"', @builder.to_s
23
+ @builder.annotate "5 it's"
24
+ assert_equal %w[-annotate 5 it's], @builder.to_a
25
25
  end
26
26
 
27
27
  def test_option_builder_with_blocks
28
28
  # Passing in basic commands produces a string
29
29
  b = MojoMagick::OptBuilder.new
30
30
  b.image_block do
31
- b.background 'red'
31
+ b.background "red"
32
32
  end
33
33
  b.image_block do
34
- b.background 'blue'
34
+ b.background "blue"
35
35
  end
36
- assert_equal '\( -background red \) \( -background blue \)', b.to_s
36
+ assert_equal ['\(', "-background", "red", '\)', '\(', "-background", "blue", '\)'], b.to_a
37
37
  end
38
38
 
39
39
  def test_option_builder_with_hex_colors
40
40
  b = MojoMagick::OptBuilder.new
41
- b.background '#000000'
42
- assert_equal '-background "#000000"', b.to_s
41
+ b.background "#000000"
42
+ assert_equal %w[-background #000000], b.to_a
43
43
  end
44
44
 
45
45
  def test_option_builder
@@ -47,80 +47,80 @@ class MojoMagickOptBuilderTest < MiniTest::Test
47
47
  b = MojoMagick::OptBuilder.new
48
48
  b.strip
49
49
  b.repage
50
- assert_equal '-strip -repage', b.to_s
50
+ assert_equal "-strip -repage", b.to_s
51
51
 
52
52
  # Chaining commands works
53
53
  b = MojoMagick::OptBuilder.new.strip.repage
54
- assert_equal '-strip -repage', b.to_s
54
+ assert_equal "-strip -repage", b.to_s
55
55
 
56
56
  # Bang (!) indicates the plus version of commands
57
57
  b = MojoMagick::OptBuilder.new
58
58
  b.repage
59
59
  b.repage!
60
- assert_equal '-repage +repage', b.to_s
60
+ assert_equal "-repage +repage", b.to_s
61
61
 
62
62
  # Accepts raw data as-is
63
63
  b = MojoMagick::OptBuilder.new
64
64
  b.opt1
65
- b << 'a ! b !'
65
+ b << "a ! b !"
66
66
  b.opt2
67
- assert_equal '-opt1 a ! b ! -opt2', b.to_s
67
+ assert_equal "-opt1 a ! b ! -opt2", b.to_s
68
68
 
69
69
  # Treats an array of raw data as different arguments
70
70
  b = MojoMagick::OptBuilder.new
71
- b << ['leave this data', 'alone']
72
- assert_equal 'leave this data alone', b.to_s
71
+ b << ["leave this data", "alone"]
72
+ assert_equal "leave this data alone", b.to_s
73
73
 
74
74
  # String includes command arguments
75
75
  b = MojoMagick::OptBuilder.new
76
- b.extent '256x256+0+0'
77
- b.crop '64x64'
78
- assert_equal '-extent 256x256+0+0 -crop 64x64', b.to_s
76
+ b.extent "256x256+0+0"
77
+ b.crop "64x64"
78
+ assert_equal %w[-extent 256x256+0+0 -crop 64x64], b.to_a
79
79
 
80
80
  # Arguments are quoted (doublequote) if appropriate
81
81
  b = MojoMagick::OptBuilder.new
82
- b.comment 'white space'
83
- b.comment 'w&b'
84
- b.crop '6x6^'
85
- assert_equal '-comment "white space" -comment "w&b" -crop "6x6^"', b.to_s
82
+ b.comment "white space"
83
+ b.comment "w&b"
84
+ b.crop "6x6^"
85
+ assert_equal ["-comment", "white space", "-comment", "w&b", "-crop", "6x6^"], b.to_a
86
86
 
87
87
  # Existing doublequotes are escaped
88
88
  b = MojoMagick::OptBuilder.new
89
89
  b.comment 'Fred "Woot" Rook'
90
- assert_equal '-comment "Fred \"Woot\" Rook"', b.to_s
90
+ assert_equal ["-comment", "Fred \"Woot\" Rook"], b.to_a
91
91
 
92
92
  # Multi-argument commands should not be quoted together
93
93
  b = MojoMagick::OptBuilder.new
94
- b.set 'comment', 'the "best" comment'
95
- assert_equal '-set comment "the \"best\" comment"', b.to_s
94
+ b.set "comment", 'the "best" comment'
95
+ assert_equal ["-set", "comment", "the \"best\" comment"], b.to_a
96
96
 
97
97
  # File and files are helper methods
98
98
  b = MojoMagick::OptBuilder.new
99
- b.files 'source.jpg', 'source2.jpg'
99
+ b.files "source.jpg", "source2.jpg"
100
100
  b.append
101
- b.crop '64x64'
102
- b.file 'dest%d.jpg'
103
- assert_equal 'source.jpg source2.jpg -append -crop 64x64 dest%d.jpg', b.to_s
101
+ b.crop "64x64"
102
+ b.file "dest%d.jpg"
103
+ assert_equal %w[source.jpg source2.jpg -append -crop 64x64 dest%d.jpg], b.to_a
104
104
 
105
105
  # Files are quoted (doublequote) if appropriate
106
106
  b = MojoMagick::OptBuilder.new
107
- b.file 'probably on windows.jpg'
108
- assert_equal '"probably on windows.jpg"', b.to_s
107
+ b.file "probably on windows.jpg"
108
+ assert_equal ["probably on windows.jpg"], b.to_a
109
109
 
110
110
  # Blob is a shortcut for the #tempfile helper method
111
111
  b = MojoMagick::OptBuilder.new
112
- b.blob 'binary data'
112
+ b.blob "binary data"
113
113
  filename = b.to_s
114
- File.open(filename, 'rb') do |f|
115
- assert_equal 'binary data', f.read
114
+ File.open(filename, "rb") do |f|
115
+ assert_equal "binary data", f.read
116
116
  end
117
117
 
118
118
  # label for text should use 'label:"the string"' if specified
119
119
  [%w[mylabel mylabel],
120
120
  ['my " label', '"my \" label"'],
121
- ['Rock it, cuz i said so!', '"Rock it, cuz i said so!"'],
121
+ ["Rock it, cuz i said so!", '"Rock it, cuz i said so!"'],
122
122
  ["it's like this", '"it\'s like this"'],
123
- ['#$%^&*', '"#$%^&*"']].each do |labels|
123
+ ["\#$%^&*", '"#$%^&*"']].each do |labels|
124
124
  b = MojoMagick::OptBuilder.new
125
125
  b.label labels[0]
126
126
  assert_equal "label:#{labels[1]}", b.to_s
@@ -1,6 +1,6 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
1
+ require_relative "test_helper"
2
2
 
3
- IDENTIFY_FONT_RESPONSE = <<~EOF.freeze
3
+ IDENTIFY_FONT_RESPONSE = <<~EOFONT
4
4
 
5
5
  Font: Zapf-Dingbats
6
6
  family: Zapf Dingbats
@@ -17,13 +17,13 @@ IDENTIFY_FONT_RESPONSE = <<~EOF.freeze
17
17
  glyphs: /Library/Fonts/Zapfino.ttf
18
18
 
19
19
 
20
- EOF
20
+ EOFONT
21
21
 
22
22
  class ParserTest < MiniTest::Test
23
23
  def test_parse_fonts
24
24
  parser = MojoMagick::Util::Parser.new
25
25
  parsed_fonts = parser.parse_fonts(IDENTIFY_FONT_RESPONSE)
26
26
  assert_equal parsed_fonts.length, 2
27
- assert_equal parsed_fonts[1].style, 'Italic'
27
+ assert_equal parsed_fonts[1].style, "Italic"
28
28
  end
29
29
  end
@@ -1,6 +1,8 @@
1
- require 'minitest/autorun'
2
- require 'minitest/pride'
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'init'))
4
- require 'fileutils'
5
- require 'tempfile'
6
- require 'rspec/expectations'
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ require "minitest/autorun"
5
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
6
+ require "fileutils"
7
+ require "tempfile"
8
+ require "rspec/expectations"
metadata CHANGED
@@ -1,17 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojo_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Midgley
8
8
  - Elliot Nelson
9
9
  - Jon Rogers
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-04 00:00:00.000000000 Z
13
+ date: 2021-01-22 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bundle-audit
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
15
43
  - !ruby/object:Gem::Dependency
16
44
  name: minitest
17
45
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +83,21 @@ dependencies:
55
83
  - !ruby/object:Gem::Version
56
84
  version: '0'
57
85
  - !ruby/object:Gem::Dependency
58
- name: simplecov
86
+ name: rubocop
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop-performance
59
101
  requirement: !ruby/object:Gem::Requirement
60
102
  requirements:
61
103
  - - ">="
@@ -76,7 +118,13 @@ executables: []
76
118
  extensions: []
77
119
  extra_rdoc_files: []
78
120
  files:
121
+ - ".circleci/config.yml"
122
+ - ".github/dependabot.yml"
79
123
  - ".gitignore"
124
+ - ".rubocop-common.yml"
125
+ - ".rubocop-performance.yml"
126
+ - ".rubocop-rspec.yml"
127
+ - ".rubocop.yml"
80
128
  - ".ruby-version"
81
129
  - Gemfile
82
130
  - Gemfile.lock
@@ -87,7 +135,6 @@ files:
87
135
  - examples/composite.rb
88
136
  - init.rb
89
137
  - lib/image_magick/fonts.rb
90
- - lib/image_magick/resource_limits.rb
91
138
  - lib/initializers/hash.rb
92
139
  - lib/mojo_magick.rb
93
140
  - lib/mojo_magick/command_status.rb
@@ -99,13 +146,13 @@ files:
99
146
  - mojo_magick.gemspec
100
147
  - test/fixtures/5742.jpg
101
148
  - test/fixtures/not_an_image.jpg
149
+ - test/fixtures/roll with it.jpg
102
150
  - test/fixtures/zero_byte_image.jpg
103
151
  - test/font_test.rb
104
152
  - test/fonts_test.rb
105
153
  - test/mojo_magick_test.rb
106
154
  - test/opt_builder_test.rb
107
155
  - test/parser_test.rb
108
- - test/resource_limits_test.rb
109
156
  - test/test_helper.rb
110
157
  homepage: http://github.com/rcode5/mojo_magick
111
158
  licenses:
@@ -127,7 +174,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
174
  requirements:
128
175
  - - ">="
129
176
  - !ruby/object:Gem::Version
130
- version: '0'
177
+ version: 2.6.0
131
178
  required_rubygems_version: !ruby/object:Gem::Requirement
132
179
  requirements:
133
180
  - - ">="
@@ -135,18 +182,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
182
  version: '0'
136
183
  requirements: []
137
184
  rubygems_version: 3.0.3
138
- signing_key:
185
+ signing_key:
139
186
  specification_version: 4
140
- summary: mojo_magick-0.5.7
187
+ summary: mojo_magick-0.6.0
141
188
  test_files:
142
189
  - test/fixtures/5742.jpg
143
190
  - test/fixtures/not_an_image.jpg
191
+ - test/fixtures/roll with it.jpg
144
192
  - test/fixtures/zero_byte_image.jpg
145
193
  - test/font_test.rb
146
194
  - test/fonts_test.rb
147
195
  - test/mojo_magick_test.rb
148
196
  - test/opt_builder_test.rb
149
197
  - test/parser_test.rb
150
- - test/resource_limits_test.rb
151
198
  - test/test_helper.rb
152
199
  ...
@@ -1,91 +0,0 @@
1
- # This module provides some mix-in methods to permit resource limitation commands in MojoMagick
2
- module ImageMagick
3
- module ResourceLimits
4
- @@resource_limits = {}
5
-
6
- # controls limits on memory and other resources for imagemagick.
7
- # possible values for type can include:
8
- # Area, Disk, File, Map, or Memory
9
- # value is byte size for everything but Disk, where it's number of files
10
- # type can be string or symbol.
11
- # Just limiting Memory will not solve problems with imagemagick going out of
12
- # control with resource consumption on certain bad files. You have to set disk,
13
- # area and map limits too. Read up on imagemagick website for more.
14
- # Different options have different units
15
- # DISK: N GB
16
- # AREA, MAP, MEMORY: N MB
17
- # FILE: N num file handles
18
- # Examples:
19
- # # set disk to 5 gigabytes limit
20
- # MiniMagick::Image::set_limit(:disk => 5)
21
- # # set memory to 32mb, map to 64mb and disk to 0
22
- # MiniMagick::Image::set_limit(:memory => 32, 'map' => 64, 'disk' => 0)
23
- def set_limits(options)
24
- options.each do |resource, value|
25
- @@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
26
- end
27
- end
28
-
29
- # remove a limit
30
- def remove_limits(*options)
31
- @@resource_limits.delete_if do |resource, _value|
32
- idx = options.index(resource)
33
- resource == options.values_at(idx)[0].to_s.downcase.to_sym if idx
34
- end
35
- end
36
-
37
- # remove limits from resources
38
- def unset_limits(options = {})
39
- @@resource_limits = {}
40
- if options[:unset_env]
41
- ENV['MAGICK_AREA_LIMIT'] = nil
42
- ENV['MAGICK_MAP_LIMIT'] = nil
43
- ENV['MAGICK_MEMORY_LIMIT'] = nil
44
- ENV['MAGICK_DISK_LIMIT'] = nil
45
- end
46
- end
47
-
48
- # returns the default limits that imagemagick is using, when run with no "-limit" parameters
49
- # options:
50
- # :show_actual_values => true (default false) - will return integers instead of readable values
51
- def get_default_limits(options = {})
52
- parse_limits(options.merge(get_current_limits: false))
53
- end
54
-
55
- # returns the limits that imagemagick is running based on any "set_limits" calls
56
- def get_current_limits(options = {})
57
- parse_limits(options.merge(get_current_limits: true))
58
- end
59
-
60
- alias get_limits get_current_limits
61
-
62
- def parse_limits(options)
63
- show_actual_values = options[:show_actual_values]
64
- if options[:get_current_limits]
65
- status = execute('identify', '-list resource')
66
- raw_limits = status.return_value
67
- else
68
- # we run a raw shell command here to obtain
69
- # limits without applying command line limit params
70
- raw_limits = `identify -list resource`
71
- end
72
- actual_values, readable_values = parser.parse_limits(raw_limits)
73
- show_actual_values ? actual_values : readable_values
74
- end # parse_limits
75
-
76
- # returns a string suitable for passing as a set of imagemagick params
77
- # that contains all the limit constraints
78
- def get_limits_as_params
79
- retval = ''
80
- # we upcase the value here for newer versions of ImageMagick (>=6.8.x)
81
- @@resource_limits.each do |type, value|
82
- retval += " -limit #{type} #{value.upcase} "
83
- end
84
- retval
85
- end
86
-
87
- def parser
88
- @parser ||= MojoMagick::Util::Parser.new
89
- end
90
- end
91
- end
@@ -1,49 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- class ResourceLimitsTest < MiniTest::Test
4
- def setup
5
- @orig_limits = MojoMagick.get_default_limits
6
- end
7
-
8
- def test_set_limits
9
- # set area to 32mb limit
10
- MojoMagick.set_limits(area: '32mb')
11
- new_limits = MojoMagick.get_current_limits
12
- assert_equal '32mb', new_limits[:area].downcase
13
- end
14
-
15
- def test_get_limits
16
- assert(@orig_limits.size >= 7)
17
- end
18
-
19
- def test_resource_limits
20
- orig_limits_test = @orig_limits.dup
21
- orig_limits_test.delete_if do |resource, _value|
22
- assert %i[throttle area map disk memory file thread time].include?(resource), "Found unexpected resource #{resource}"
23
- true
24
- end
25
- assert_equal 0, orig_limits_test.size
26
- end
27
-
28
- def test_get_current_limits
29
- # remove limits on area
30
- MojoMagick.remove_limits(:area)
31
- new_limits = MojoMagick.get_current_limits
32
- assert_equal @orig_limits[:area], new_limits[:area]
33
- end
34
-
35
- def test_set_limits_again
36
- # set memory to 64 mb, disk to 0 and
37
- MojoMagick.set_limits(memory: '64mb', disk: '0b')
38
- new_limits = MojoMagick.get_current_limits(show_actual_values: true)
39
- assert_equal 61, new_limits[:memory]
40
- assert_equal 0, new_limits[:disk]
41
- end
42
-
43
- def test_unset_limits
44
- # return to original/default limit values
45
- MojoMagick.unset_limits
46
- new_limits = MojoMagick.get_current_limits
47
- assert_equal @orig_limits, new_limits
48
- end
49
- end