Class: Dragonfly::ActiveModelExtensions::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/dragonfly/active_record_extensions/attachment.rb

Defined Under Namespace

Classes: InvaidGeometryOrStyleNameError

Instance Method Summary collapse

Instance Method Details

#current_stylesObject



23
24
25
# File 'lib/dragonfly/active_record_extensions/attachment.rb', line 23

def current_styles
  parent_model.class.dragonfly_styles_for_attributes[attribute_name.to_sym] || {}
end

#style(style_name_or_geometry, format = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dragonfly/active_record_extensions/attachment.rb', line 6

def style style_name_or_geometry, format=nil
  scope = case style_name_or_geometry
  when Symbol # style_name => :small_rectangle
    style current_styles[style_name_or_geometry], format
  when String # geometry => '100x80'
    job.thumb style_name_or_geometry
  when Array # geometry + format => ['100x80', :gif]
    style *style_name_or_geometry
  when Proc  # Proc for style => lambda { thumb('100x80').process(:greyscale).encode(:png) }
    job.instance_eval &style_name_or_geometry
  else
    raise InvaidGeometryOrStyleNameError
  end
  scope = scope.encode(format) if format
  scope
end