Sha256: a396c2a993c675d5b1ec16610b99a9ebf73407b8f4991415770485355269b21f

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

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)
            has_members(member_klasses)
          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

2 entries across 2 versions & 1 rubygems

Version Path
groupify-0.9.0 lib/groupify/adapter/mongoid/model.rb
groupify-0.8.0 lib/groupify/adapter/mongoid/model.rb