Sha256: 755bdae94b7493a628f4675e6c43e814cb321544477421d813d1afe26a5c862a

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'roles_active_record/strategy/single'

module RoleStrategy::ActiveRecord
  module AdminFlag    
    def self.default_role_attribute
      :admin_flag
    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) 
        case role_name.downcase.to_sym
        when :admin
          where(role_attribute => true)
        else
          where(role_attribute => false)
        end          
      end
    end

    module Implementation
      include Roles::ActiveRecord::Strategy::Single

      def new_role role
        role = role.kind_of?(Array) ? role.flatten.first : role
        role.admin?
      end
      
      def get_role
        self.send(role_attribute) ? strategy_class.admin_role_key : strategy_class.default_role_key
      end 
      
      def present_roles *roles
        roles = roles.flat_uniq
        roles.map{|role| role ? :admin : :guest}
      end   
      
      def set_empty_role
        self.send("#{role_attribute}=", false)
      end      

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roles_active_record-0.3.1 lib/roles_active_record/strategy/single/admin_flag.rb