Skip to content

Instantly share code, notes, and snippets.

@miketierney
Last active December 12, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketierney/4740904 to your computer and use it in GitHub Desktop.
Save miketierney/4740904 to your computer and use it in GitHub Desktop.
require 'storable'
require 'faker'
module ViewHelpers
# …
# Data Faking
class Subscriber < Storable
field :id => Integer
field :first_name
field :last_name
field :created_at
def full_name
"#{self.first_name} #{self.last_name}"
end
def self.all
ObjectSpace.each_object(self).to_a.sort{|a,b| a.id <=> b.id}
end
def self.bootstrap
fixtures = YAML.load ERB.new(File.read(file)).result
fixtures.each do |f|
from_hash(f[1]) # from_hash is provided by Storable
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment