Created
February 18, 2014 12:32
-
-
Save joakimk/9070106 to your computer and use it in GitHub Desktop.
Using the app/records organization method with minimapper.
This file contains 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
require "minimapper/mapper" | |
class ApplicationMapper < Minimapper::Mapper | |
def record_class | |
record_name = self.class.name.gsub(/Mapper/, "Record") | |
record_name.constantize | |
end | |
end |
This file contains 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
# 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 file contains 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
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