Module: ActsAsAvatar::ClassMethods

Defined in:
lib/acts_as_avatar/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_avatar(**options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/acts_as_avatar/class_methods.rb', line 9

def acts_as_avatar(**options)
  random_image_engine = options.delete(:random_image_engine)
  inline_svg_engine = options.delete(:inline_svg_engine)

  define_singleton_method :random_image_engine do
    random_image_engine.presence || ActsAsAvatar.configuration.random_image_engine
  end

  define_singleton_method :inline_svg_engine do
    inline_svg_engine.presence || ActsAsAvatar.configuration.inline_svg_engine
  end

  has_one :avatar, as: :avatarable, class_name: "ActsAsAvatar::Avatar"
  accepts_nested_attributes_for :avatar
  delegate :current_avatar, :default_avatar, :upload_avatar, to: :avatar
  include InstanceMethods
  # after_create_commit { create_avatar }
end