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_folder ⇒ Object
Returns the value of attribute assets_folder.
-
#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.
-
#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 |
# 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] @assets_folder = [:assets_folder] ? Pathname.new([:assets_folder]) : nil @http_cache_max_age = [: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 .key?(:save_resized) @save_resized = true end end if [:processor] self.processor = [:processor] end end |
Instance Attribute Details
#assets_folder ⇒ Object
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_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 |
#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
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 |