Skip to content
This repository was archived by the owner on Apr 18, 2018. It is now read-only.
This repository was archived by the owner on Apr 18, 2018. It is now read-only.

Add ActiveModel::Callbacks to Curator::Model #31

@jamesottaway

Description

@jamesottaway

I'm just getting started with Curator, which I'm really excited about, but one interesting feature which I think would make it even more compelling is to add callbacks or hooks, similar to what ActiveRecord has done.

http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

In my case, I've got a Post model with a title and slug, and I'm trying to default the slug if one was not explicitly passed, but respect an explicit one if it is passed in. My code looks something like this:

class Post
  include Curator::Model

  attr_accessor :title, :slug

  def initialize(args={})
    args[:slug] ||= args[:title].to_slug
    super(args)
  end
end

I'd love to be able to hook into an after_create callback which would mean I don't need to override initialize while still calling super after I've made cahnges to args.

Does this seem like something valuable for Curator?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions