hassox (owner)

Revisions

gist: 89607 Download_button fork
public
Public Clone URL: git://gist.github.com/89607.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Transfigr.add(:xml, :active_record) do
  priority 0.7
 
  guard do |obj, opts|
    obj.ancestors.include?(ActiveRecord)
  end
 
  def format(opts)
    obj.to_xml(opts)
  end
end
 
Transfigr.add(:xml, :active_record_admin) do
  priority 0.8
  
  guard do |obj, opts|
    ActiveRecord === obj && opts[:user] && opts[:user].admin?
  end
 
  def format(opts)
    # do admin stuff here
  end
end
 
Transfigr.format!(:xml, @post) #=> uses the :active_record formatter
Transfigr.format!(:xml, @post, :user => pleb_user) # uses the active_record formatter
Transfigr.format!(:xml, @post, :user => admin_user) # uses the active_record_admin formatter
Transfigr.format!(:xml, @post, :type => :active_record_admin) # Use the active_recrod_admin bypassing the guard