Sha256: 3f10301784c9fe5370fa5a90b425e28a052f3115d7dd834c62fd7abf83410a67
Contents?: true
Size: 807 Bytes
Versions: 6
Compression:
Stored size: 807 Bytes
Contents
require "factory_girl_rails" namespace :human_attrs do desc "Show generated human attributes for ActiveRecord models" task :show, [:model] => [:environment] do |_t, args| model_name = args[:model].tableize.singularize model = args[:model].classify.constantize instance = begin FactoryGirl.build(model_name) rescue nil end if instance instance.id = 1 if instance.respond_to?(:id) instance.created_at = DateTime.current if instance.respond_to?(:created_at) instance.updated_at = DateTime.current if instance.respond_to?(:updated_at) end result = model.humanizers.map do |m| value = begin instance.send(m) rescue nil end !!value ? "#{m} => #{value}" : m end puts result.join("\n") end end
Version data entries
6 entries across 6 versions & 1 rubygems