poleica 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2JkOTZiMjQ2MmQ3Y2MyYmI3OTI2N2I2MWUzNDI5ZTM5YTE2MmZhOA==
4
+ ZTkyNGUxMWEyYWRkNGQ1Y2Y2OTVhNDg2ZDEwNTM3MjQ2MTIxNGVmYg==
5
5
  data.tar.gz: !binary |-
6
- MzdmZDljYWRmMGFiNWJjNDZmMGJlMjE4NWE4YjljY2I5YTJiYjdlMA==
6
+ ZTBmZjcyYTYwMjFjMzhmZThhZjZmODE5MmY0MGE4Yjg2OWY2OGUzYw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MmNhMTE3YjQ3MjE4OTdhMjFlOTBiYjQyN2Y0ZmJhM2Y0YzU1ZDhiMDNlZjA1
10
- MjNlZDEwNmFjM2RkMWY4OTRiNmI0OGE2Y2FmZThkMzdhY2ZkMDEzMDNjZGY2
11
- MDIzZTNhOTM0NTU5MGYzZDgwNGFiNDQzODA1NjA3YmUzMTFjYjc=
9
+ NTQ3ZTgwMDA4MzAwMGNkNDE2MTdhZGM5ODQxMDM1YjM1OTc0YmVhNzhmZWRi
10
+ YmJkMjQ3OGUwZDI0MTZkYjcyOWY4Nzg4YjdkNTc5NTlmMTEzYWE0YzdkNGVh
11
+ NGYwMTA3NDY3ZGIyOWE4ZDkwYzFlODFmMjY0ZDFlNzFjOWQzNWU=
12
12
  data.tar.gz: !binary |-
13
- YzBkMGJmNjgxMmJiZTNhNDNiMWM0MGQwOTIwYTczODdmMTRiNGFhMjY5ZTZm
14
- MDk2ZWMzNDU5Y2E4MjMwMGQ1YjFmM2M0NGUwMjU1N2FiODQ4NmYyMDk0ZWY0
15
- OWM0MjYyMjNhNzY3MmQ5MTlkOWMxNWZmMTEyNTNhNWYwMTlmYTM=
13
+ OTVkMTc4YjU5YWFkYWQ4NGEwYTdkNTg4OWQzNzk4YjVlYWUzZmM1YTg4ODg5
14
+ OTAwYzMyNzllMTUwZDRjZjVjYWJlMzZiODQ1MmMwNzZiNmNjMjE0OWYwOTFk
15
+ NDFmZjk3Zjk2ZGNjYmI3NjE3ZDgzZDMzZmViYWQ4MzQ4Yzk5MmU=
data/.travis.yml CHANGED
@@ -7,8 +7,19 @@ rvm:
7
7
  - jruby-19mode
8
8
  before_script:
9
9
  - sudo apt-get update -qq
10
- - sudo apt-get install -qq graphicsmagick libreoffice
10
+ - sudo apt-get install -qq libreoffice
11
+ - wget http://78.108.103.11/MIRROR/ftp/GraphicsMagick/1.3/GraphicsMagick-1.3.18.tar.gz
12
+ - tar -xvf GraphicsMagick-1.3.18.tar.gz
13
+ - cd GraphicsMagick-1.3.18
14
+ - ./configure
15
+ - make
16
+ - sudo make install
17
+ - sudo ln -s /usr/local/bin/gm /usr/bin/gm
11
18
  script:
12
19
  - rake
20
+ matrix:
21
+ allow_failures:
22
+ - rvm: jruby-19mode
23
+ - rvm: rbx-19mode
13
24
  notifications:
14
25
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
+ # Poleica 0.9.9 (6 August 2013)
2
+ * Add configure method to Poleica, with timeout option
1
3
  # Poleica 0.9.8 (5 August 2013)
2
4
  * Add timeout (2 mins) on LibreOffice and GraphicsMagick execution
3
5
  # Poleica 0.9.7 (4 August 2013)
data/README.md CHANGED
@@ -11,15 +11,15 @@
11
11
 
12
12
  __Ubuntu__ :
13
13
 
14
- ```
15
- apt-get install graphicsmagick libreoffice
16
- ```
14
+ Look at .travis.yml file
17
15
 
18
16
  __MacOS__ :
19
17
 
20
18
  ```
21
19
  brew install ghostscript graphicsmagick
22
20
  ```
21
+ Download [LibreOffice](http://www.libreoffice.org/download) and install it.
22
+
23
23
 
24
24
  __Then__ :
25
25
 
@@ -33,7 +33,6 @@ or in __Gemfile__ :
33
33
  gem 'poleica'
34
34
  ```
35
35
 
36
- Then download [LibreOffice](http://www.libreoffice.org/download) and install it.
37
36
  ## Concept
38
37
 
39
38
  _ -> PDF -> Image
@@ -58,7 +57,7 @@ Poleica.new(file_path).to_png(width: 400, weight: 400)
58
57
 
59
58
  ## Dependencies
60
59
 
61
- - GraphicsMagick (gm) >= 1.3.11
60
+ - GraphicsMagick (gm) >= 1.3.18 (for auto-rotate)
62
61
  - LibreOffice
63
62
 
64
63
  ## Requirements
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Poleica
3
+ # Configuration class
4
+ class Configuration
5
+ attr_accessor :timeout
6
+
7
+ def initialize
8
+ self.timeout = 120
9
+ end
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration) if block_given?
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+ end # module Poleica
@@ -5,6 +5,10 @@ module Poleica
5
5
  class Coercive
6
6
  include Poleica::Converters::Utils
7
7
 
8
+ COMPATIBLE_TYPES = [
9
+ Types::All
10
+ ]
11
+
8
12
  # TODO Think about another way of declare return types
9
13
  TYPE_RETURNED_BY_METHOD = {
10
14
  to_pdf: Types::PDF,
@@ -58,8 +62,7 @@ module Poleica
58
62
  polei.compatible_convert_methods.map do |m|
59
63
  ret_type = TYPE_RETURNED_BY_METHOD[m.to_sym]
60
64
  next unless ret_type
61
- convs = Poleica::Convertible.
62
- compatible_converters_by_type(ret_type)
65
+ convs = Poleica::Convertible.compatible_converters_by_type(ret_type)
63
66
  convs.map { |conv| { m.to_sym => conv } }
64
67
  end.compact.flatten(1)
65
68
  end
@@ -3,14 +3,13 @@ module Poleica
3
3
  # Conversion Logic, given a type it can search for compatible converters
4
4
  module Convertible
5
5
 
6
- CONVERTERS = [
7
- Converters::GraphicsMagick,
8
- Converters::LibreOffice
9
- ]
6
+ CONVERTERS = Poleica::Converters
7
+ .constants.map { |c| Poleica::Converters.const_get(c) } -
8
+ [Poleica::Converters::Utils]
10
9
 
11
10
  def method_missing(method, *args, &block)
12
- extension, options = Converters::Utils
13
- .extract_extension_and_options(method, args)
11
+ extension, options =
12
+ Converters::Utils.extract_extension_and_options(method, args)
14
13
  return convert_to_extension(extension, options) if extension
15
14
  super
16
15
  end
@@ -20,7 +19,7 @@ module Poleica
20
19
  converter.send("to_#{extension}".to_sym, options)
21
20
  end
22
21
 
23
- def converter_to_extension(extension, filter = :mimetype)
22
+ def converter_to_extension(extension)
24
23
  compatible_converter = compatible_converters.find do |converter|
25
24
  converter.method_defined?(:"to_#{extension}")
26
25
  end
@@ -55,6 +54,5 @@ module Poleica
55
54
  def methods_for_converter(converter)
56
55
  converter.instance_methods(false).map(&:to_s)
57
56
  end
58
-
59
57
  end # module Convertible
60
58
  end # module Poleica
@@ -1,9 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Poleica
3
3
  module Converters
4
- # The General converter, it handles any file type.
4
+ # The General converter, it handles any file type and return null for
5
+ # unknown conversion
5
6
  class General
6
7
 
8
+ COMPATIBLE_TYPES = [
9
+ Types::All
10
+ ]
11
+
7
12
  attr_reader :polei
8
13
 
9
14
  def initialize(polei)
@@ -13,6 +18,10 @@ module Poleica
13
18
  def to_bin(options = {})
14
19
  File.binread(polei.path)
15
20
  end
21
+
22
+ def method_missing(method, *args, &block)
23
+ super unless method =~ /^to_/
24
+ end
16
25
  end # class General
17
26
  end # module Converters
18
- end # module Poleica
27
+ end # module Poleica
@@ -9,8 +9,6 @@ module Poleica
9
9
  module Utils
10
10
  HOST_OS ||= (defined?('RbConfig') ? RbConfig : Config)::CONFIG['host_os']
11
11
 
12
- DEFAULT_TIMEOUT = 120
13
-
14
12
  def windows?
15
13
  !!HOST_OS.match(/mswin|windows|cygwin/i)
16
14
  end
@@ -48,12 +46,15 @@ module Poleica
48
46
  Shellwords.shellescape(string)
49
47
  end
50
48
 
51
- def exec_with_timeout(cmd, timeout = DEFAULT_TIMEOUT, no_stdout = true)
49
+ def exec_with_timeout(cmd,
50
+ timeout = Poleica.configuration.timeout,
51
+ no_stdout = true)
52
52
  cmd << ' >/dev/null' if no_stdout
53
53
  pid = Process.spawn(cmd)
54
54
  Timeout.timeout(timeout) { Process.wait(pid) }
55
- rescue Timeout::Error
56
- Process.kill('TERM', pid)
55
+ rescue Timeout::Error => e
56
+ Process.kill('KILL', pid)
57
+ raise e
57
58
  end
58
59
  end # module Utils
59
60
  end # module Converters
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Poleica
3
+ # rubocop:disable all
4
+ module Types
5
+ All = Poleica::Types.constants.map { |c| Poleica::Types.const_get(c) }
6
+ end # module Types
7
+ # rubocop:enable all
8
+ end # module Poleica
@@ -3,10 +3,14 @@ module Poleica
3
3
  module Types
4
4
  # Null Object Pattern Type, this is the type returned if no compatible
5
5
  # types are found
6
- class Null
6
+ class General
7
+
8
+ COMPATIBLE_MIMETYPES = []
9
+ COMPATIBLE_EXTENSIONS = []
10
+
7
11
  def initialize(file_path)
8
12
 
9
13
  end
10
- end # class Null
14
+ end # class General
11
15
  end # module Types
12
- end # module Poleica
16
+ end # module Poleica
@@ -14,19 +14,13 @@ module Poleica
14
14
  def file_type
15
15
  @file_type ||= (detect_type_with_extension ||
16
16
  detect_type_with_mimetype ||
17
- Types::Null).new(path)
17
+ Types::General).new(path)
18
18
  end
19
19
 
20
20
  private
21
21
 
22
22
  MIMETYPE_EXTRACT_REGEX = /([^;:]+)/
23
23
 
24
- TYPES = [
25
- Types::Image,
26
- Types::Document,
27
- Types::PDF
28
- ]
29
-
30
24
  def extract_mimetype
31
25
  `file -b --mime '#{path}'`.strip[MIMETYPE_EXTRACT_REGEX] || ''
32
26
  end
@@ -36,13 +30,13 @@ module Poleica
36
30
  end
37
31
 
38
32
  def detect_type_with_extension
39
- TYPES.find do |type|
33
+ Types::All.find do |type|
40
34
  type::COMPATIBLE_EXTENSIONS.include?(file_extension)
41
35
  end
42
36
  end
43
37
 
44
38
  def detect_type_with_mimetype
45
- TYPES.find do |type|
39
+ Types::All.find do |type|
46
40
  type::COMPATIBLE_MIMETYPES.include?(file_mimetype)
47
41
  end
48
42
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Poleica
3
- VERSION ||= '0.9.8'
3
+ VERSION ||= '0.9.9'
4
4
  end # module Poleica
data/lib/poleica.rb CHANGED
@@ -7,16 +7,17 @@ module Poleica
7
7
  end # module Poleica
8
8
 
9
9
  require 'poleica/version'
10
+ require 'poleica/configuration'
10
11
 
11
12
  require 'poleica/types/pdf'
12
- require 'poleica/types/null'
13
13
  require 'poleica/types/image'
14
14
  require 'poleica/types/document'
15
15
  require 'poleica/types/typeable'
16
+ require 'poleica/types/general'
17
+ require 'poleica/types/all'
16
18
 
17
19
  require 'poleica/converters/utils'
18
20
  require 'poleica/converters/general'
19
- require 'poleica/converters/null'
20
21
  require 'poleica/converters/coercive'
21
22
  require 'poleica/converters/graphics_magick'
22
23
  require 'poleica/converters/libre_office'
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'test_helper'
3
+ # Test the Configuration Converter Module
4
+ class ConfigurationTest < Minitest::Test
5
+ def test_timeout_configuration
6
+ start_time = Time.now
7
+ Poleica.configure { |config| config.timeout = 1 }
8
+ Poleica::Converters::Utils.exec_with_timeout('sleep 2') rescue nil
9
+ duration = Time.now - start_time
10
+ assert(duration < 2)
11
+ ensure
12
+ Poleica.configure { |config| config.timeout = 120 }
13
+ end
14
+ end
@@ -8,4 +8,18 @@ class GeneralTest < Minitest::Test
8
8
  gif_polei = Poleica::Polei.new(gif_path)
9
9
  assert_equal(gif_data, gif_polei.to_bin)
10
10
  end
11
- end # class GeneralTest
11
+
12
+ def test_it_returns_nil_on_to_method
13
+ method_name = :to_random
14
+ file = Minitest::Mock.new
15
+ converter = Poleica::Converters::General.new(file)
16
+ assert_nil(converter.send(method_name))
17
+ end
18
+
19
+ def test_it_raise_no_method_error_on_other_calls
20
+ method_name = :random
21
+ file = Minitest::Mock.new
22
+ converter = Poleica::Converters::General.new(file)
23
+ assert_raises(NoMethodError) { converter.send(method_name) }
24
+ end
25
+ end # class GeneralTest
@@ -2,10 +2,16 @@
2
2
  require 'test_helper'
3
3
  # Test the Utils Converter Module
4
4
  class UtilsTest < Minitest::Test
5
- def test_exect_with_timeout
5
+ def test_exec_with_timeout
6
6
  start_time = Time.now
7
- Poleica::Converters::Utils.exec_with_timeout('sleep 2', 1)
7
+ Poleica::Converters::Utils.exec_with_timeout('sleep 2', 0.1) rescue nil
8
8
  duration = Time.now - start_time
9
9
  assert(duration < 2)
10
10
  end
11
+
12
+ def test_exec_with_timeout_exception
13
+ assert_raises(Timeout::Error) do
14
+ Poleica::Converters::Utils.exec_with_timeout('sleep 2', 0.1)
15
+ end
16
+ end
11
17
  end
@@ -26,7 +26,7 @@ class TypeableTest < Minitest::Test
26
26
  def test_that_it_extracts_a_type_object
27
27
  expected_classes = [
28
28
  Poleica::Types::Document,
29
- Poleica::Types::Null,
29
+ Poleica::Types::General,
30
30
  Poleica::Types::Document,
31
31
  Poleica::Types::Image
32
32
  ]
@@ -39,7 +39,7 @@ class TypeableTest < Minitest::Test
39
39
  def test_that_it_returns_null_type_by_default
40
40
  mp3_path = "#{Support.support_path}/files/example.mp3"
41
41
  type_class = Poleica::Polei.new(mp3_path).file_type.class
42
- assert_equal(type_class, Poleica::Types::Null)
42
+ assert_equal(type_class, Poleica::Types::General)
43
43
  end
44
44
 
45
45
  ## Helpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poleica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Lyset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-05 00:00:00.000000000 Z
11
+ date: 2013-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -55,29 +55,30 @@ files:
55
55
  - README.md
56
56
  - Rakefile
57
57
  - lib/poleica.rb
58
+ - lib/poleica/configuration.rb
58
59
  - lib/poleica/converters/coercive.rb
59
60
  - lib/poleica/converters/convertible.rb
60
61
  - lib/poleica/converters/general.rb
61
62
  - lib/poleica/converters/graphics_magick.rb
62
63
  - lib/poleica/converters/libre_office.rb
63
- - lib/poleica/converters/null.rb
64
64
  - lib/poleica/converters/utils.rb
65
65
  - lib/poleica/pathable.rb
66
66
  - lib/poleica/polei.rb
67
+ - lib/poleica/types/all.rb
67
68
  - lib/poleica/types/archive.rb
68
69
  - lib/poleica/types/document.rb
70
+ - lib/poleica/types/general.rb
69
71
  - lib/poleica/types/image.rb
70
- - lib/poleica/types/null.rb
71
72
  - lib/poleica/types/pdf.rb
72
73
  - lib/poleica/types/typeable.rb
73
74
  - lib/poleica/version.rb
74
75
  - poleica.gemspec
76
+ - test/poleica/configuration_test.rb
75
77
  - test/poleica/converters/coercive_test.rb
76
78
  - test/poleica/converters/convertible_test.rb
77
79
  - test/poleica/converters/general_test.rb
78
80
  - test/poleica/converters/graphics_magick_test.rb
79
81
  - test/poleica/converters/libre_office_test.rb
80
- - test/poleica/converters/null_test.rb
81
82
  - test/poleica/converters/utils_test.rb
82
83
  - test/poleica/pathable_test.rb
83
84
  - test/poleica/polei_test.rb
@@ -114,12 +115,12 @@ signing_key:
114
115
  specification_version: 4
115
116
  summary: A general converter and thumbnail creator
116
117
  test_files:
118
+ - test/poleica/configuration_test.rb
117
119
  - test/poleica/converters/coercive_test.rb
118
120
  - test/poleica/converters/convertible_test.rb
119
121
  - test/poleica/converters/general_test.rb
120
122
  - test/poleica/converters/graphics_magick_test.rb
121
123
  - test/poleica/converters/libre_office_test.rb
122
- - test/poleica/converters/null_test.rb
123
124
  - test/poleica/converters/utils_test.rb
124
125
  - test/poleica/pathable_test.rb
125
126
  - test/poleica/polei_test.rb
@@ -1,17 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- module Poleica
3
- module Converters
4
- # Null Object Pattern, this is the converter returned if no compatible
5
- # converters are found
6
- class Null
7
- attr_reader :polei
8
- def initialize(polei)
9
- @polei = polei
10
- end
11
-
12
- def method_missing(method, *args, &block)
13
- super unless method =~ /^to_/
14
- end
15
- end # class Null
16
- end # module Converters
17
- end # module Poleica
@@ -1,18 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'test_helper'
3
- # Test the Null Converter Module
4
- class NullTest < Minitest::Test
5
- def test_it_returns_nil_on_to_method
6
- method_name = :to_random
7
- file = Minitest::Mock.new
8
- converter = Poleica::Converters::Null.new(file)
9
- assert_nil(converter.send(method_name))
10
- end
11
-
12
- def test_it_raise_no_method_error_on_other_calls
13
- method_name = :random
14
- file = Minitest::Mock.new
15
- converter = Poleica::Converters::Null.new(file)
16
- assert_raises(NoMethodError) { converter.send(method_name) }
17
- end
18
- end # class NullTest