callisto 0.9 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require "delegate"
2
+
1
3
  module Callisto
2
4
 
3
5
  class Configuration
@@ -10,32 +12,43 @@ module Callisto
10
12
  :max_workers => 4
11
13
  }
12
14
 
15
+ THUMBNAIL = {
16
+ :quality => 90
17
+ }
18
+
19
+ SHELL = {}
20
+
13
21
  end
14
22
 
15
23
  attr_accessor :thumbnail_defaults
16
24
 
17
25
  def initialize
18
- self.thumbnail_defaults = {}
19
- load_defaults
26
+ reset
20
27
  end
21
28
 
22
- def load_defaults
23
- Pool.settings = Defaults::POOL
29
+ def reset
30
+ self.thumbnail_defaults = Defaults::THUMBNAIL.clone
31
+ Pool.settings = Defaults::POOL.clone
32
+ Shell.bin_path = Defaults::SHELL.clone[:bin_path]
24
33
  end
25
34
 
26
35
  def max_workers=(val)
27
36
  Pool.settings.max_workers = val
28
37
  end
29
38
 
39
+ def bin_path=(val)
40
+ Shell.bin_path = val
41
+ end
42
+
30
43
  def method_missing(method, *args, &block)
31
44
  if /^thumbnail_(?<name>[a-z\_]+)(?<setter>=)?/ =~ method
32
45
  if setter
33
- self.thumbnail_defaults[name] = args.first
46
+ self.thumbnail_defaults[name.to_sym] = args.first
34
47
  else
35
- thumbnail_defaults[name]
48
+ thumbnail_defaults[name.to_sym]
36
49
  end
37
50
  else
38
- super
51
+ super(method, *args, &block)
39
52
  end
40
53
  end
41
54
 
@@ -17,11 +17,11 @@ module Callisto
17
17
  :identifier => proc { |entry| entry.object_id },
18
18
  :callback => proc { |entry| entry.call }
19
19
  }
20
- @@settings = OpenStruct.new(defaults.merge(options))
20
+ @settings = OpenStruct.new(defaults.merge(options))
21
21
  end
22
22
 
23
23
  def settings
24
- @@settings
24
+ @settings
25
25
  end
26
26
 
27
27
  end
@@ -5,7 +5,11 @@ module Callisto
5
5
  attr_accessor :executable, :arguments
6
6
 
7
7
  def self.bin_path=(path)
8
- @@bin_path = path
8
+ @bin_path = path
9
+ end
10
+
11
+ def self.bin_path
12
+ @bin_path
9
13
  end
10
14
 
11
15
  def initialize(executable, arguments)
@@ -14,11 +18,7 @@ module Callisto
14
18
  end
15
19
 
16
20
  def command
17
- prefix = if defined?(@@bin_path)
18
- File.join(@@bin_path, executable)
19
- else
20
- executable
21
- end
21
+ prefix = File.join(*[self.class.bin_path, executable].compact)
22
22
  "#{prefix} #{arguments}"
23
23
  end
24
24
 
@@ -25,7 +25,7 @@ module Callisto
25
25
  location = File.join(root_path, prefix)
26
26
  if !File.exist?(save_path)
27
27
  FileUtils.mkdir_p(location) unless File.directory?(location)
28
- task = Shell.new("convert", "#{file_path} -strip -quality #{quality || 90} -resize #{size}#{flag} #{crop} #{save_path}")
28
+ task = Shell.new("convert", "#{file_path} -strip -quality #{quality} -resize #{size}#{flag} #{crop} #{save_path}")
29
29
  pid = Callisto::Pool.instance << task
30
30
  Callisto::Pool.instance.wait(pid)
31
31
  end
@@ -1,3 +1,3 @@
1
1
  module Callisto
2
- VERSION = "0.9"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -3,6 +3,10 @@ require File.expand_path("../minitest_helper", __FILE__)
3
3
 
4
4
  describe "Configuration" do
5
5
 
6
+ before do
7
+ Callisto.configuration.reset
8
+ end
9
+
6
10
  it "should assign max workers to pool" do
7
11
  Callisto.configure do |config|
8
12
  config.max_workers = 13
@@ -20,4 +24,16 @@ describe "Configuration" do
20
24
  Callisto.configuration.thumbnail_quality.must_equal 75
21
25
  end
22
26
 
27
+ it "can be reset" do
28
+ default_size = Callisto::Configuration::Defaults::THUMBNAIL[:size]
29
+ default_quality = Callisto::Configuration::Defaults::THUMBNAIL[:quality]
30
+ Callisto.configure do |config|
31
+ config.thumbnail_size = "20x45"
32
+ config.thumbnail_quality = 75
33
+ end
34
+ Callisto.configuration.reset
35
+ Callisto.configuration.thumbnail_size.must_equal default_size
36
+ Callisto.configuration.thumbnail_quality.must_equal default_quality
37
+ end
38
+
23
39
  end
@@ -6,3 +6,8 @@ def reset_pool
6
6
  Callisto::Pool.settings = {}
7
7
  Callisto::Pool.reset_instance
8
8
  end
9
+
10
+ def cleanup(path)
11
+ matcher = File.join(path, "*.*")
12
+ Dir[matcher].each { |entry| File.unlink(entry) }
13
+ end
@@ -1,16 +1,11 @@
1
1
  require "minitest/autorun"
2
2
  require File.expand_path("../minitest_helper", __FILE__)
3
3
 
4
- def cleanup(path)
5
- matcher = File.join(path, "*.*")
6
- Dir[matcher].each { |entry| File.unlink(entry) }
7
- end
8
-
9
4
  describe "Thumbnail" do
10
5
 
11
6
  before do
12
7
  reset_pool
13
- Callisto.configuration.load_defaults
8
+ Callisto.configuration.reset
14
9
  end
15
10
 
16
11
  describe "when saving" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: callisto
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000Z
12
+ date: 2012-04-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &25241560 !ruby/object:Gem::Requirement
16
+ requirement: &27777500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *25241560
24
+ version_requirements: *27777500
25
25
  description: Image thumbnails on the fly
26
26
  email:
27
27
  - daniel@thegeek.ro