Skip to content

Instantly share code, notes, and snippets.

@joakimk
Created February 18, 2014 12:32
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 joakimk/9070106 to your computer and use it in GitHub Desktop.
Save joakimk/9070106 to your computer and use it in GitHub Desktop.
Using the app/records organization method with minimapper.
require "minimapper/mapper"
class ApplicationMapper < Minimapper::Mapper
def record_class
record_name = self.class.name.gsub(/Mapper/, "Record")
record_name.constantize
end
end
# Support EmployeeRecord instead of Employee in
# associations without needing to specify class_name.
module ActiveRecord
module Reflection
class AssociationReflection < MacroReflection
private
def derive_class_name
"#{name.to_s.singularize}_record".to_s.camelize
end
end
end
end
This is how we've setup models in a medium sized app using minimapper.
It makes it simpler to access the records in console, just EmployeeRecord instead of Employee.
Also makes the mapper classes simpler.
Also add "app/records" to config.autoload_paths in config/application.rb to get this to work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment