Class: Avatar::Source::FileColumnSource

Inherits:
Object
  • Object
show all
Includes:
AbstractSource, FileColumnHelper
Defined in:
lib/avatar/source/file_column_source.rb

Overview

For use with the FileColumn Rails plugin.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_field = :avatar) ⇒ FileColumnSource

Returns a new instance of FileColumnSource.

Raises:

  • (ArgumentError)


13
14
15
16
# File 'lib/avatar/source/file_column_source.rb', line 13

def initialize(default_field = :avatar)
  raise ArgumentError.new('default_field cannot be nil') if default_field.nil?
  @default_field = default_field
end

Instance Attribute Details

#default_fieldObject

Returns the value of attribute default_field.



11
12
13
# File 'lib/avatar/source/file_column_source.rb', line 11

def default_field
  @default_field
end

Instance Method Details

#avatar_url_for(person, options = {}) ⇒ Object

Returns nil if person is nil; otherwise, returns the (possibly nil) result of url_for_image_column, passing in all of options except :file_column_field. Options:

  • :file_column_field - the image file column within person; by default, :avatar

  • :file_column_version - one of the versions of the file_column; no default

If :file_column_version is not specified, all other options are passed to url_for_image_column as options (see FileColumnHelper)



25
26
27
28
29
30
31
32
# File 'lib/avatar/source/file_column_source.rb', line 25

def avatar_url_for(person, options = {})
  return nil if person.nil?
  options = parse_options(person, options)
  field = options.delete(:file_column_field) || default_field
  return nil if field.nil? || person.send(field).nil?
  options = options[:file_column_version] || options
  url_for_image_column(person, field, options)
end

#parse_options(person, options) ⇒ Object



34
35
36
# File 'lib/avatar/source/file_column_source.rb', line 34

def parse_options(person, options)
  options
end