Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.