0

Is it possible to use the Amoeba gem within a Concern? Currently I'm getting this error when I try to run it inside a Concern:

undefined method `amoeba' for Amoeba:Module

The same code works fine inside the actual models but I want to DRY it up, since it is highly similar between 2 of my models... Here is what the Concern looks like:

module Amoeba
  extend ActiveSupport::Concern

  amoeba do
    enable
    customize(lambda { |original, clone|
      clone.uid        = SecureRandom.hex(2)
      clone.activities = []

    if original.class.name == "Widget"
      clone.bookings   = []
    end

    if orignal.class.name == "Flotsam"
      clone.remaining  = 100
      if original.expiration.past?
        clone.expiration = Date.today + 5.years
      end
    end

    if original.icon.present?
      clone.icon = original.icon
    end
    if original.pdf.present?
      clone.pdf = original.pdf
    end
  })
end
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
John Trichereau
  • 626
  • 9
  • 22

1 Answers1

1

amoeba is a class method. With ActiveSupport::Concern it should be called within included block

module Amoeba
  extend ActiveSupport::Concern
  included do
    amoeba do 
    ....
    end
  end

ActiveSupport::Concern

dre-hh
  • 7,840
  • 2
  • 33
  • 44