Class Paperclip::Style
In: lib/paperclip/style.rb
Parent: Object

The Style class holds the definition of a thumbnail style, applying whatever processing is required to normalize the definition and delaying the evaluation of block parameters until useful context is available.

Methods

[]   []=   convert_options   geometry   new   processor_options   processors   whiny   whiny?  

Attributes

attachment  [R] 
format  [R] 
name  [R] 

Public Class methods

Creates a Style object. name is the name of the attachment, definition is the style definition from has_attached_file, which can be string, array or hash

[Source]

    # File lib/paperclip/style.rb, line 14
14:     def initialize name, definition, attachment
15:       @name = name
16:       @attachment = attachment
17:       if definition.is_a? Hash
18:         @geometry = definition.delete(:geometry)
19:         @format = definition.delete(:format)
20:         @processors = definition.delete(:processors)
21:         @other_args = definition
22:       else
23:         @geometry, @format = [definition, nil].flatten[0..1]
24:         @other_args = {}
25:       end
26:       @format  = nil if @format.blank?
27:     end

Public Instance methods

Supports getting and setting style properties with hash notation to ensure backwards-compatibility eg. @attachment.styles[:large][:geometry]@ will still work

[Source]

    # File lib/paperclip/style.rb, line 73
73:     def [](key)
74:       if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
75:         send(key)
76:       elsif defined? @other_args[key]
77:         @other_args[key]
78:       end
79:     end

[Source]

    # File lib/paperclip/style.rb, line 81
81:     def []=(key, value)
82:       if [:name, :convert_options, :whiny, :processors, :geometry, :format].include?(key)
83:         send("#{key}=".intern, value)
84:       else
85:         @other_args[key] = value
86:       end
87:     end

[Source]

    # File lib/paperclip/style.rb, line 47
47:     def convert_options
48:       attachment.send(:extra_options_for, name)
49:     end

returns the geometry string for this style if a proc has been supplied, we call it here

[Source]

    # File lib/paperclip/style.rb, line 53
53:     def geometry
54:       @geometry.respond_to?(:call) ? @geometry.call(attachment.instance) : @geometry
55:     end

Supplies the hash of options that processors expect to receive as their second argument Arguments other than the standard geometry, format etc are just passed through from initialization and any procs are called here, just before post-processing.

[Source]

    # File lib/paperclip/style.rb, line 60
60:     def processor_options
61:       args = {}
62:       @other_args.each do |k,v|
63:         args[k] = v.respond_to?(:call) ? v.call(attachment) : v
64:       end
65:       [:processors, :geometry, :format, :whiny, :convert_options].each do |k|
66:         (arg = send(k)) && args[k] = arg
67:       end
68:       args
69:     end

retrieves from the attachment the processors defined in the has_attached_file call (which method (in the attachment) will call any supplied procs) There is an important change of interface here: a style rule can set its own processors by default we behave as before, though.

[Source]

    # File lib/paperclip/style.rb, line 33
33:     def processors
34:       @processors || attachment.processors
35:     end

retrieves from the attachment the whiny setting

[Source]

    # File lib/paperclip/style.rb, line 38
38:     def whiny
39:       attachment.whiny
40:     end

returns true if we‘re inclined to grumble

[Source]

    # File lib/paperclip/style.rb, line 43
43:     def whiny?
44:       !!whiny
45:     end

[Validate]