ref: dockerize
plugins/open_graph/models/open_graph_plugin/track_config.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
class OpenGraphPlugin::TrackConfig < OpenGraphPlugin::Track Types = { activity: 'ActivityTrackConfig', enterprise: 'EnterpriseTrackConfig', community: 'CommunityTrackConfig', # TODO: not yet implemented #friend: 'FriendTrackConfig', } # define on subclasses (required) class_attribute :track_name def self.track_enabled_field "#{self.track_name}_track_enabled" end # true if do not depend on records (e.g. EnterpriseTrackConfig depends on friends) # redefine on subclasses class_attribute :static_trackers self.static_trackers = false def self.enabled? context, actor settings = actor.send "#{context}_settings" settings.send "#{self.track_name}_track_enabled" end scope :tracks_to_profile, lambda { |profile, exclude_actor=nil| scope = where object_data_id: profile.id, object_data_type: profile.class.base_class scope = scope.where context: OpenGraphPlugin.context scope = scope.includes :tracker scope = scope.where ['tracker_id <> ?', exclude_actor.id] if exclude_actor scope } # redefine on subclasses def self.trackers_to_profile profile tracks = self.tracks_to_profile profile tracks = tracks.where type: self tracks.map(&:tracker) end def self.profile_tracks profile profile.send self.association end def self.profile_track_objects profile self.profile_tracks(profile).map(&:object_data).compact end end |