This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> user.name = "John" | |
> user.save | |
> user.name_previously_changed? | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> user.name = "John" | |
> user.save | |
> user.previous_changes | |
=> {"name"=>["Frank", "John"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> user = User.first | |
> user.name | |
=> "Frank" | |
> user.name = "John" | |
> user.name_changed? | |
=> true | |
> user.name_change | |
=> ["Frank", "John"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PreviouslyDirty | |
extend ActiveSupport::Concern | |
included do | |
attribute_method_suffix '_previously_changed?' | |
end | |
private | |
# Handle <tt>*_previously_changed?</tt> for +method_missing+. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
adapter: mysql2 | |
encoding: utf8 | |
database: my_db | |
pool: 20 | |
username: | |
password: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :data do | |
MyApp::RakeData.tables.each do |table| | |
desc "scrubs #{table} table data" | |
task "scrub_#{table}" do | |
string_attributes = table.classify.constantize.columns.map {|c| c.name if [:string, :text].include?(c.type) }.compact | |
setters = [] | |
update_string = "UPDATE #{table} SET " | |
string_attributes.each do |attribute| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyApp | |
module RakeData | |
extend Self | |
HILARIOUS_STRING = 'Gangster lorem ipsum from http://lorizzle.nl/' | |
def tables | |
["list", "of", "table", "names"] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :data do | |
desc "scrubs all strings in every table" | |
task :scrub => :environment do | |
unless Rails.env.development? | |
raise "This should only ever be run in development!" | |
end | |
tables = ActiveRecord::Base.connection.tables - ["schema_migrations"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rabl.render(Event.first, 'events/event') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters