Sha256: e876c63aa9b2ac7857f629765e0802bd5afea58eb579856f66ca41c79ab702a9

Contents?: true

Size: 1.26 KB

Versions: 34

Compression:

Stored size: 1.26 KB

Contents

module SocialStream
  module Models
    # Models that have author, user_author and owner, properties saved in {Channel}.
    # Currently {Activity} and {ActivityObject}
    module Channeled
      # Add the method {#channeled} to ActiveRecord
      module ActiveRecord
        extend ActiveSupport::Concern

        module ClassMethods
          # This class is channeled. See {Channel}
          def channeled
            include SocialStream::Models::Channeled
          end
        end
      end

      extend ActiveSupport::Concern

      included do
        # Channeled models are subtypes of {Channel}
        # Author, owner and user_author are defined in its channel
        subtype_of :channel,
                   :belongs => { :dependent => nil }

        before_validation :check_existing_channel
      end

      protected

      # Use existing channel, do not create a new one
      def check_existing_channel
        return unless channel!.new_record?

        existing_channel =
          Channel.
            where(:author_id      => author_id,
                  :owner_id       => owner_id,
                  :user_author_id => user_author_id).
            first

        return if existing_channel.blank?

        self.channel = existing_channel
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
social_stream-0.23.4 base/lib/social_stream/models/channeled.rb
social_stream-base-0.17.3 lib/social_stream/models/channeled.rb
social_stream-0.23.3 base/lib/social_stream/models/channeled.rb
social_stream-base-0.17.2 lib/social_stream/models/channeled.rb
social_stream-0.23.2 base/lib/social_stream/models/channeled.rb
social_stream-base-0.17.1 lib/social_stream/models/channeled.rb
social_stream-0.23.1 base/lib/social_stream/models/channeled.rb
social_stream-base-0.17.0 lib/social_stream/models/channeled.rb
social_stream-0.22.1 base/lib/social_stream/models/channeled.rb
social_stream-base-0.16.4 lib/social_stream/models/channeled.rb
social_stream-0.22.0 base/lib/social_stream/models/channeled.rb
social_stream-base-0.16.3 lib/social_stream/models/channeled.rb
social_stream-0.21.4 base/lib/social_stream/models/channeled.rb
social_stream-base-0.16.2 lib/social_stream/models/channeled.rb
social_stream-0.21.3 base/lib/social_stream/models/channeled.rb
social_stream-0.21.2 base/lib/social_stream/models/channeled.rb
social_stream-0.21.1 base/lib/social_stream/models/channeled.rb
social_stream-base-0.16.1 lib/social_stream/models/channeled.rb
social_stream-0.21.0 base/lib/social_stream/models/channeled.rb
social_stream-base-0.16.0 lib/social_stream/models/channeled.rb