# MyApp/app/models/blorgh/post.rb
# overrides Blorgh's original Post model
class Blorgh::Post < ActiveRecord::Base
include Blorgh::Concerns::Models::Post
def time_since_created
Time.current - created_at
end
end
# Blorgh/app/models/post.rb
# this class is overriden by the MyApp Post model
class Post < ActiveRecord::Base
include Blorgh::Concerns::Models::Post
end
# Blorgh/app/concerns/models/post
module Blorg::Concerns::Models::Post
extend ActiveSupport::Concern
# 'included do' causes the code within to be evaluated in the conext
# where it is included, rather be executed in the module's context.
included do
attr_accessor :author_name
belongs_to :author, :class_name => "User"
before_save :set_author
private
def set_author
self.author = User.find_or_create_by_name(author_name)
end
end
# methods defined here will be instance methods by default
def some_method
'some method string'
end
module ClassMethods
def some_class_method
'some class method string'
end
end
end