Version Callbacks for ToSBack Policies

Our ToSBack policies now have some automatic versioning when the “detail” attribute is changed!

Here’s an example policy in my development environment. Its current version is stored as an attribute in the policy model (detail), but it’s also represented in the versions model:

1.9.3-p327 :001 > pol = Policy.first

1.9.3-p327 :009 >   pol.detail
 => " <p>500px is founded on the principle of helping people discover new photos and photographers..."

1.9.3-p327 :010 > pol.versions.each {|v| puts "#{v.created_at} - #{v.previous_crawl}"}
2013-01-29 07:11:20 UTC - Current Version

I implemented some tests and callback methods today that make tracking changes easier:

1.9.3-p327 :011 > pol.update_attributes(detail:"new crawl 1")
...
=> true
1.9.3-p327 :012 > pol.update_attributes(detail:"new crawl 2")
...
=> true 
1.9.3-p327 :013 > pol.update_attributes(detail:"new crawl 3")
...
=> true 

1.9.3-p327 :014 > pol.versions.each {|v| puts "#{v.created_at} - #{v.previous_crawl}"}
2013-01-29 07:11:20 UTC -  <p>500px is founded on the principle of helping people discover new photos and photographers...
2013-02-01 22:36:36 UTC - new crawl 1
2013-02-01 22:36:46 UTC - new crawl 2
2013-02-01 22:36:49 UTC - Current Version

1.9.3-p327 :015 > pol.detail
=> "new crawl 3"

Each version is stored in the versions table with it’s creation date, and all we did was update the policy! You can see all the code on Github!

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>