Sha256: 64fb8d651f29eab926ea612e91c8d61d351b15d08ba717d6f4d020f43065a34c
Contents?: true
Size: 1.75 KB
Versions: 34
Compression:
Stored size: 1.75 KB
Contents
module SocialStream #:nodoc: module Models # Common methods for models having many {SocialStream::Models::Subtype subtypes}. # Currently, there are two {SocialStream::Models::Supertype supertypes}: # * {Actor}: participates in the social network and has {Tie Ties} with other actors. Its subtypes are {SocialStream::Models::Subject subjects}, such as {User} or {Group} # * {ActivityObject}: created and managed by {Actor Actors} in {Activity Activities}. Its subtypes are {SocialStream::Models::Object objects}, like {Post} or {Comment} module Supertype # Include the class method {#supertype_of} to ActiveRecord::Base module ActiveRecord extend ActiveSupport::Concern module ClassMethods # This class is a supertype. Subtype classes are known as name def supertype_of name @subtypes_name = name include SocialStream::Models::Supertype end end end extend ActiveSupport::Concern included do subtypes.each do |s| has_one s, :dependent => :destroy end end module ClassMethods def subtypes_name @subtypes_name end def subtypes SocialStream.__send__ subtypes_name.to_s.tableize # SocialStream.subjects # in Actor end end def subtype_instance if __send__("#{ self.class.subtypes_name }_type").present? # if object_type.present? object_class = __send__("#{ self.class.subtypes_name }_type") # object_class = object_type # => "Video" __send__ object_class.constantize.base_class.to_s.underscore # __send__ "document" end # end end end end end
Version data entries
34 entries across 34 versions & 2 rubygems