Sha256: 304cac0e8d701e54b2ef9ac2f0d143ef458fadd7aaaac4bc6e564114f1592e73

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Poms
  # Mixin for a class that has ancestors.
  module HasAncestors
    module ClassMethods
    end

    module InstanceMethods
      def series
        return @series if @series
        return [] if descendant_of.blank?
        descendant_series = descendant_of.reject do |obj|
          obj.class != Poms::Series
        end
        if descendant_series.blank?
          descendant_of
        else
          descendant_series
        end
      end

      def serie
        series.first
      end

      def serie_mid
        return nil if serie.nil?
        serie.mid_ref || serie.mid
      end

      def ancestor_mids
        return @ancestor_mids if @ancestor_mids
        @ancestor_mids = (descendant_of_mids +
          episode_of_mids).flatten.compact.uniq
      end

      def descendant_of_mids
        descendant_of.map(&:mid_ref)
      rescue
        []
      end

      def episode_of_mids
        episode_of.map(&:mid_ref)
      rescue
        []
      end
    end

    def self.included(receiver)
      receiver.extend ClassMethods
      receiver.send :include, InstanceMethods
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
poms-1.2.2 lib/poms/has_ancestors.rb
poms-1.2.1 lib/poms/has_ancestors.rb
poms-1.2.0 lib/poms/has_ancestors.rb
poms-1.1.0 lib/poms/has_ancestors.rb
poms-1.0.1 lib/poms/has_ancestors.rb
poms-1.0.0 lib/poms/has_ancestors.rb