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
31
32
33
34
35
36
37
38
# 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]
  @http_cache_max_age = options[:http_cache_max_age] || 86400 # 1 day
  @max_dimension      = options[:max_dimension] || 4000
  @logger             = options[:logger]

  self.assets_folders = options[:assets_folders] if options[:assets_folders]

  if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
    @cache_folder ||= Rails.root.join('tmp', 'rack_resize_cache')
    unless options.key?(:assets_folders)
      self.assets_folders = {
        "assets"  => Rails.root.join("app/assets/images"),
        "uploads" => Rails.root.join("public/uploads"),
      }
    end
    unless options.key?(:save_resized)
      @save_resized = true
    end
  end

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

Instance Attribute Details

#assets_foldersObject

Returns the value of attribute assets_folders.



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

def assets_folders
  @assets_folders
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

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#max_dimensionObject

Returns the value of attribute max_dimension.



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

def max_dimension
  @max_dimension
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



60
61
62
63
64
65
66
67
68
69
# File 'lib/rack_resize/configuration.rb', line 60

def processor_instance
  @processor_instance ||= case @processor
                          when :mini_magick then RackResize::Processors::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