Hi all,

I'm developing a CMS system based on Sequel that uses the concept of
'revisions' to manage the publish workflow and need some advice about
the best way to implement this in Sequel.

Let me explain a bit more. The editable content of the CMS is held in
a table called simply "content". When a user decides to make some
changes live the system duplicates the "content" table into another
table named after the next revision number, e.g. "revision_023". This
"revision_023" table is then used by the Content model in place of
"content" on the public site, thus sand-boxing the published content
from the edited content.

As a system it works really, really well but my current method for
dynamically changing the table name within a certain context is very
fragile and very hacky. Basically I have this monkey patch:

(This is the new version that I had to fix for the 3.30 release.
Having to make this fix has prompted me to (finally) ask for some
advice on how to do it properly.)

module Sequel
  class Dataset
 
alias_method :sequel_quote_identifier_append, :quote_identifier_append

    def quote_identifier_append(sql, name)
      if name == :content or name == "content"
        name = Content.current_revision_table
      end
      sequel_quote_identifier_append(sql, name)
    end
  end
end

Nasty huh?

What I need to achieve is the following:

Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
`content`">

Content.with_revision(23) do
  Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
`revision_023`">

  Content.with_revision(24) do
    Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
`revision_024`">

    Content.with_editable do
      Content.dataset #=> #<Sequel::Mysql2::Dataset: "SELECT * FROM
`content`">
    end
  end
end

Does anyone know the right way to code this into a self-contained
Sequel plugin? Any ideas greatly appreciated...

Thanks,

Garry


-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to