Sha256: cb9c5a014cea3ff21643679d090ae34d11975de71bad051b6e5c7b9845706656

Contents?: true

Size: 892 Bytes

Versions: 2

Compression:

Stored size: 892 Bytes

Contents

module GroupedMessage

  def self.included(base)
    base.class_eval {
      has_groups

      include InstanceMethods
      alias_method_chain :possible_readers, :groups
      alias_method_chain :inactive_readers, :groups
      
      extend ClassMethods
      class << self
        alias_method_chain :functional, :groups
      end
    }
  end
  
  module InstanceMethods
    def possible_readers_with_groups
      groups.any? ? Reader.in_groups(groups).active : possible_readers_without_groups
    end
    def inactive_readers_with_groups
      groups.any? ? Reader.in_groups(groups).inactive : inactive_readers_without_groups
    end
  end
  
  module ClassMethods
    def functional_with_groups(function, group=nil)
      messages = for_function(function)
      if group
        messages.belonging_to(group).first
      else
        messages.ungrouped.first
      end
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
radiant-reader_group-extension-1.2.4 lib/grouped_message.rb
radiant-reader_group-extension-1.2.3 lib/grouped_message.rb