Sha256: 045e9a373216282dfd7c0abc4d6129b7d348e318b8310a7e00c0c6a4c2dd75e1

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

module Roles::Base
  def valid_roles_are(*role_list)
    strategy_class.valid_roles = role_list.to_symbols
  end
end

module Roles
  module DataMapper  
    def self.included(base) 
      base.extend Roles::Base
      base.extend ClassMethods
      base.orm_name = :data_mapper
    end

    module ClassMethods
      
      MAP = {
        :admin_flag   => "property :admin_flag,   ::DataMapper::Property::Flag[:admin, :default]",
        :roles_mask   => "property :roles_mask,   Integer, :default => 1",
        :role_string  => "property :role_string,  String",
        :roles_string => "property :roles_string, String"
      }
      
      def strategy name, options=nil
        if options == :default && MAP[name]
          instance_eval MAP[name] 
        end
        role_strategy name, options
      end    
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roles_data_mapper-0.1.3 lib/roles_data_mapper/base.rb
roles_data_mapper-0.1.2 lib/roles_data_mapper/base.rb
roles_data_mapper-0.1.1 lib/roles_data_mapper/base.rb
roles_data_mapper-0.1.0 lib/roles_data_mapper/base.rb