module ActsAsGravatar::Methods

Methods of ActiveRecord::Base.

Public Instance Methods

gravatar_image(options = {}) click to toggle source

Generate a URL of Gravatar image.

@example

user = User.find(1)
# get url with default options.
url = user.gravatar_url

# with option.
url = user.gravatar_url {
  :column        => :email,                                # email column of Model.
  :default_image => nil,                                   # default_image.(URL or gravatar default image param.)
  :force_default => false,                                 # force the default image.
  :image_type    => ActsAsGravatar::Enums::ImageType::PNG, # image_type. (JPG/JPEG/GIF/PNG)
  :rating        => ActsAsGravatar::Enums::Rating::PG,     # rating. (G/PG/R/X)
  :secure        => false,                                 # secure protocol. (https).
  :size          => 80,                                    # image size.
}

@param options [Hash] Option of gravatar image.

@return [String] Url of Gravatar image.

# File lib/acts_as_gravatar.rb, line 61
def gravatar_image(options = {})
  opts  = gravatar_option(options)
  email = send(opts[:column])

  ActsAsGravatar::Gravatar.generate_image(email, opts)
end
gravatar_profile(options = {}) click to toggle source

Generate a URL of Gravatar profile. @example

user = User.find(1)
# get url with default options.
profile = user.gravatar_profile

# with option.
profile = user.gravatar_profile {
  :column        => :email
}

@param options [Hash] Option of gravatar profile.

@return [String] tag of Gravatar image.

# File lib/acts_as_gravatar.rb, line 82
def gravatar_profile(options = {})
  opts  = gravatar_option(options)
  email = send(opts[:column])

  ActsAsGravatar::Gravatar.generate_profile(email, opts)
end

Private Instance Methods

gravatar_option(merge_options = {}) click to toggle source

Get options of gravatar. @note return default options merge merge_options.

@param merge_options [Hash] Options of gravatar. @return [Hash] Options of gravatar.

# File lib/acts_as_gravatar.rb, line 95
def gravatar_option(merge_options = {})
  self.class.instance_variable_get(:@acts_as_gravatar_default_options).merge(merge_options)
end