Class: RackResize::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_resize/configuration.rb

Constant Summary collapse

PROCESSORS =
%i[sips vips mini_magick imlib2].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack_resize/configuration.rb', line 11

def initialize(options = {})
  @processor          = options[:processor] || RUBY_PLATFORM.include?('darwin') ? :sips : :mini_magick
  @save_resized       = options.key?(:save_resized) ? options[:save_resized] : false
  @default_quality    = options[:default_quality] || 95
  @cache_folder       = options[:cache_folder]
  @assets_folder      = options[:assets_folder] ? Pathname.new(options[:assets_folder]) : nil
  @http_cache_max_age = options[:http_cache_max_age] || 86400 # 1 day

  if defined?(Rails)
    @cache_folder ||= Rails.root.join('tmp', 'rack_resize_cache')
    @assets_folder ||= Rails.root.join('app', 'assets', 'images')
    unless options.key?(:save_resized)
      @save_resized = true
    end
  end

  if options[:processor]
    self.processor = options[:processor]
  end
end

Instance Attribute Details

#assets_folderObject

Returns the value of attribute assets_folder.



7
8
9
# File 'lib/rack_resize/configuration.rb', line 7

def assets_folder
  @assets_folder
end

#cache_folderObject

Returns the value of attribute cache_folder.



7
8
9
# File 'lib/rack_resize/configuration.rb', line 7

def cache_folder
  @cache_folder
end

#default_qualityObject

Returns the value of attribute default_quality.



7
8
9
# File 'lib/rack_resize/configuration.rb', line 7

def default_quality
  @default_quality
end

#http_cache_max_ageObject

Returns the value of attribute http_cache_max_age.



7
8
9
# File 'lib/rack_resize/configuration.rb', line 7

def http_cache_max_age
  @http_cache_max_age
end

#processorObject

Returns the value of attribute processor.



6
7
8
# File 'lib/rack_resize/configuration.rb', line 6

def processor
  @processor
end

#save_resizedObject Also known as: save_resized?

Returns the value of attribute save_resized.



7
8
9
# File 'lib/rack_resize/configuration.rb', line 7

def save_resized
  @save_resized
end

Instance Method Details

#processor_instanceObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/rack_resize/configuration.rb', line 41

def processor_instance
  @processor_instance ||= case @processor
                          when :mini_magick then RackResize::MiniMagick.new
                          when :vips        then RackResize::Processors::Vips.new
                          when :sips        then RackResize::Processors::Sips.new
                          when :imlib2      then RackResize::Processors::Imlib2.new
                          else
                            raise "RackResize - Unknow image processor #{@processor.inspect}"
                          end
end