Skip to content
Snippets Groups Projects
Commit 1fdc9e0d authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

refactoring models to concerns

parent e9b72f31
No related branches found
No related tags found
No related merge requests found
class Collection < ActiveRecord::Base
include Reviewable
include Sociable
include Followable
has_many :collection_items
has_many :collection_items, as: :collectionable
has_many :collections, through: :collection_items, source: :collectionable, source_type: 'Collection'
has_many :learning_objects, through: :collection_items, source: :collectionable, source_type: 'LearningObject'
belongs_to :owner, polymorphic: true
has_many :reviews, as: :reviewable
has_many :views, as: :viewable
has_many :downloads, as: :downloadable
has_many :likes, as: :likeable
has_many :shares, as: :shareable
has_many :follows, as: :followable
def owner?(candidate)
owner == candidate
......
module Followable
extend ActiveSupport::Concern
included do
has_many :follows, as: :followable
end
end
\ No newline at end of file
module Reviewable
extend ActiveSupport::Concern
included do
has_many :reviews, as: :reviewable
end
end
\ No newline at end of file
module Sociable
extend ActiveSupport::Concern
included do
has_many :views, as: :viewable
has_many :downloads, as: :downloadable
has_many :likes, as: :likeable
has_many :shares, as: :shareable
end
end
\ No newline at end of file
class LearningObject < ActiveRecord::Base
include Metadatable
include Reviewable
include Sociable
has_and_belongs_to_many :topics
......@@ -7,12 +9,6 @@ class LearningObject < ActiveRecord::Base
has_many :collections, through: :collection_items
has_many :complaints
has_many :reviews, as: :reviewable
has_many :views, as: :viewable
has_many :downloads, as: :downloadable
has_many :likes, as: :likeable
has_many :shares, as: :shareable
belongs_to :publisher, polymorphic: true
......
class User < ActiveRecord::Base
include RepositoriesProxy
include Followable
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
......@@ -18,29 +19,13 @@ class User < ActiveRecord::Base
has_many :downloads
has_many :likes
has_many :shares
has_many :follows
has_many :follows, as: :followable
after_create :default_role
has_attached_file :avatar, styles: {medium: "300x300>", thumb: "60x60>"}, default_url: lambda { |image| ActionController::Base.helpers.asset_path('user-anon.png') }
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
# def collections
# #public_collections = collection_repository.all(Collections::UserPublicContext.new(self))
# # private_collections = collection_repository.all(Collections::UserPrivateContext.new(self))
# #@collections = public_collections + private_collections
# end
#
# def bookmarks
# collection_repository.bookmarks self
# end
#
# def learning_objects
# learning_object_repository.all self
# end
def is_admin?
roles.each do |role|
return true if role.name == "admin"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment