Platinum Partner

PrettyConditions

// PrettyConditions allows you to easily print a report based on a condition for an ActiveRecord subclass


class ActiveRecord::Base
  def self.pretty_conditions(hash)
    meta_def hash[:name] do
      array = []
      puts "#{hash[:message]}:"
      puts "------------------"
      self.find(:all, :conditions => hash[:conditions]).each do |record|
        module_eval %[puts record.#{hash[:column_name]}]
        array << record
      end
      puts "------------------"
      puts "Total: #{array.size}"
      puts "------------------"
    end
  end
end



class Youth < ActiveRecord::Base
  pretty_conditions :name => 'unsponsored', :column_name => 'name', :message => "Unsponsored Youth", :conditions => "sponsor LIKE '%XXX%'"
  pretty_conditions :name => 'touchgroup_leaders', :column_name => 'name', :message => "Touchgroup Leaders", :conditions => ["touchgroup =?",'t']
  pretty_conditions :name => 'vegitarians', :column_name => 'name', :message => "Vegitarians", :conditions => ["vegitarian =?",'t'] 
end

Youth.unsponsored
Youth.touchgroup_leaders
Youth.vegitarians


Output:

saurasaurusrex:~/software cdcarter$ ruby actions.rb
Unsponsored Youth:
------------------
Hannah Gilbert
Jesse Lavercombe
Zach Adams
Danika Zabertini
------------------
Total: 4
------------------

Touchgroup Leaders:
------------------
Leland McKeeman
Marlee Leebrick-Stryker
Meggie Huges-Morrison
------------------
Total: 3
------------------

Vegitarians:
------------------
Marlee Leebrick-Stryker
Meggie Huges-Morrison
Amelia Nybakke
Ethan Edl
Maggie Heath
------------------
Total: 5
------------------
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}