Created
January 19, 2012 11:50
-
-
Save juniorz/1639562 to your computer and use it in GitHub Desktop.
Rails 3 Auto-concerner
This file contains hidden or 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
class User < ActiveRecord::Base | |
end |
This file contains hidden or 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
# Suas engines podem contribuir para a app principal usando Extensions | |
# AwesomeEngine::Extension.concern! aplica todos os <Model>Concern que ele possui | |
# ao respectivo Model de maneira "unloadable". | |
# Isso quer dizer que ao modificar sua Extension, tudo que você precisa é | |
# fazer reload! no console. | |
# <3 <3 <3 <3 | |
#app/models/post.rb | |
class Post < ActiveRecord::Base | |
belongs_to :user | |
end | |
#lib/blog_post/extensions/post_extension.rb | |
class PostExtension < AwesomeEngine::Extension | |
module UserConcern | |
included do | |
has_many :posts | |
end | |
end | |
end | |
#lib/blog_post/engine.rb | |
module BlogPost | |
class Engine < Rails::Engine | |
include AwesomeEngine::EngineConcern | |
config.to_prepare do | |
PostExtension.concern! | |
end | |
end | |
end |
This file contains hidden or 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
#app/models/comment.rb | |
class Comment < ActiveRecord::Base | |
belongs_to :post | |
end | |
#lib/blog_comment/extensions/comment_extension.rb | |
class CommentExtension < AwesomeEngine::Extension | |
module PostConcern | |
included do | |
has_many :comments | |
end | |
end | |
module UserConcern | |
included do | |
has_many :comments, :through => :posts | |
end | |
end | |
end | |
#lib/blog_comment/engine.rb | |
module BlogComment | |
class Engine < Rails::Engine | |
include AwesomeEngine::EngineConcern | |
config.to_prepare do | |
CommentExtension.concern! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment