On Saturday, May 17, 2014 6:55:48 PM UTC-7, Giovanni Sakti wrote:
>
> For something like this on my code
>
> class Master::User < Sequel::Model
> ...
>   # Concerns
>   include BasicAuth
>   include BasicAuthToken
> ...
> end
>
> module BasicAuth
>   extend ActiveSupport::Concern
> ...
>   included do
>     def before_save
>       p "do something here"
>       super
>     end
>   end
> ...
> end
>
> module BasicAuthToken
>   extend ActiveSupport::Concern
> ...
>   included do
>     def before_save
>       p "do something here 2"
>       super
>     end
>   end
> ...
> end
>
> What I expect is "do something here" and "do something here2" both to be 
> printed, but before_save hook in BasicAuthToken will override the one in 
> BasicAuth. 
> Therefore, is the only way to achieve something like this is to use 
> HookClassMethods ?
>

I don't understand why you just wouldn't do this:

class Master::User < Sequel::Model
  include BasicAuth
  include BasicAuthToken
end

module BasicAuth
    def before_save
      p "do something here"
      super
    end
end

module BasicAuthToken
    def before_save
      p "do something here 2"
      super
    end
end

This should work fine and result in both messages being printed before save.

Without knowing how ActiveSupport::Concern works, I'm guessing if you want 
to keep using it, you should move the before_save definition outside the 
included block.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to