Sha256: 478024aa0524b2c167317d0886ba439d0ed259864bd51cb9643b7e15239ca913

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

module RoleStrategy::Mongoid
  module RoleString    
    def self.default_role_attribute
      :role_string
    end

    def self.included base
      base.extend ClassMethods
    end

    module ClassMethods
      def role_attribute
        strategy_class.roles_attribute_name.to_sym
      end 

      def in_role(role_name) 
        where(role_attribute => role_name)
      end
    end

    
    module Implementation 
      def role_attribute
        strategy_class.roles_attribute_name
      end 
                  
      # assign roles
      def roles=(*roles)
        self.role = roles.select_labels.first.to_s
      end 
      
      def role= role_name
        if role_name.kind_of_label? && valid_role?(role_name)
          self.send("#{role_attribute}=", role_name.to_s) 
        end        
      end

      # query assigned roles
      def roles
        role = self.send(role_attribute)
        [role.to_sym]
      end
      alias_method :roles_list, :roles
    end

    extend Roles::Generic::User::Configuration
    configure :num => :single
  end
end


Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
roles_mongoid-0.2.4 lib/roles_mongoid/strategy/single/role_string.rb
roles_for_mongoid-0.2.3 lib/roles_mongoid/strategy/single/role_string.rb
roles_for_mongoid-0.2.2 lib/roles_mongoid/strategy/single/role_string.rb
roles_for_mongoid-0.2.1 lib/roles_mongoid/strategy/single/role_string.rb
roles_for_mongoid-0.2.0 lib/roles_mongoid/strategy/single/role_string.rb