Skip to content

Instantly share code, notes, and snippets.

@pechorin
Created January 14, 2011 09:55
Show Gist options
  • Save pechorin/779429 to your computer and use it in GitHub Desktop.
Save pechorin/779429 to your computer and use it in GitHub Desktop.
yes_no_conditions_creator = lambda {|yes_or_no,field_name|
if yes_or_no == 'yes'
{:conditions => "books.#{field_name.to_s} = true"}
elsif yes_or_no == 'no'
{:conditions => "books.#{field_name.to_s} = false or books.#{field_name.to_s} is null"}
else
{}
end
}
named_scope :by_period_assigned, lambda {|yes_or_no| yes_no_conditions_creator.call(yes_or_no, :period_assigned)}
named_scope :by_priority_assigned, lambda {|yes_or_no| yes_no_conditions_creator.call(yes_or_no, :priority_assigned)}
named_scope :by_is_technically_copied, lambda {|yes_or_no| yes_no_conditions_creator.call(yes_or_no, :is_technically_copied)}
named_scope :by_verification_completed, lambda {|yes_or_no| yes_no_conditions_creator.call(yes_or_no, :verification_completed)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment