Sha256: 9cc6547116bcc560a8254f355366ace164a8d2bce5d46c1aaffa64530319b396

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module Groupify
  module Mongoid
    module Model
      extend ActiveSupport::Concern

      included do
        def none; where(:id => nil); end
      end

      module ClassMethods
        def groupify(type, opts = {})
          send("acts_as_#{type}", opts)
        end

        def acts_as_group(opts = {})
          include Groupify::Mongoid::Group

          if (member_klass = opts.delete :default_members)
            self.default_member_class = member_klass.to_s.classify.constantize
          end

          if (member_klasses = opts.delete :members)
            member_klasses.each do |member_klass|
              has_members(member_klass)
            end
          end
        end

        def acts_as_group_member(opts = {})
          @group_class_name = opts[:group_class_name] || Groupify.group_class_name
          include Groupify::Mongoid::GroupMember
        end

        def acts_as_named_group_member(opts = {})
          include Groupify::Mongoid::NamedGroupMember
        end
      end
    end
  end
end

Mongoid::Document.send :include, Groupify::Mongoid::Model

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
groupify-0.7.2 lib/groupify/adapter/mongoid/model.rb
groupify-0.7.1 lib/groupify/adapter/mongoid/model.rb
groupify-0.7.0 lib/groupify/adapter/mongoid/model.rb