Class: RackResize::Configuration
- Inherits:
-
Object
- Object
- RackResize::Configuration
- Defined in:
- lib/rack_resize/configuration.rb
Constant Summary collapse
- PROCESSORS =
%i[sips vips mini_magick imlib2].freeze
Instance Attribute Summary collapse
-
#assets_folders ⇒ Object
Returns the value of attribute assets_folders.
-
#cache_folder ⇒ Object
Returns the value of attribute cache_folder.
-
#default_quality ⇒ Object
Returns the value of attribute default_quality.
-
#http_cache_max_age ⇒ Object
Returns the value of attribute http_cache_max_age.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_dimension ⇒ Object
Returns the value of attribute max_dimension.
-
#processor ⇒ Object
Returns the value of attribute processor.
-
#save_resized ⇒ Object
(also: #save_resized?)
Returns the value of attribute save_resized.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #processor_instance ⇒ Object
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( = {}) @processor = [:processor] || RUBY_PLATFORM.include?('darwin') ? :sips : :mini_magick @save_resized = .key?(:save_resized) ? [:save_resized] : false @default_quality = [:default_quality] || 95 @cache_folder = [:cache_folder] @http_cache_max_age = [:http_cache_max_age] || 86400 # 1 day @max_dimension = [:max_dimension] || 4000 @logger = [:logger] self.assets_folders = [:assets_folders] if [:assets_folders] if defined?(Rails) && Rails.respond_to?(:root) && Rails.root @cache_folder ||= Rails.root.join('tmp', 'rack_resize_cache') unless .key?(:assets_folders) self.assets_folders = { "assets" => Rails.root.join("app/assets/images"), "uploads" => Rails.root.join("public/uploads"), } end unless .key?(:save_resized) @save_resized = true end end if [:processor] self.processor = [:processor] end end |
Instance Attribute Details
#assets_folders ⇒ Object
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_folder ⇒ Object
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_quality ⇒ Object
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_age ⇒ Object
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 |
#logger ⇒ Object
Returns the value of attribute logger.
7 8 9 |
# File 'lib/rack_resize/configuration.rb', line 7 def logger @logger end |
#max_dimension ⇒ Object
Returns the value of attribute max_dimension.
7 8 9 |
# File 'lib/rack_resize/configuration.rb', line 7 def max_dimension @max_dimension end |
#processor ⇒ Object
Returns the value of attribute processor.
6 7 8 |
# File 'lib/rack_resize/configuration.rb', line 6 def processor @processor end |
#save_resized ⇒ Object 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_instance ⇒ Object
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 |