Sha256: 9a29be7d63ab9432ac6934dc4cf362a9bacae05224af01e8a7ce129c9910e956

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require 'roles_data_mapper/strategy/single'

module RoleStrategy::DataMapper
  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
        all(:role_string => role_name)
      end
    end

    module Implementation 
      include Roles::DataMapper::Strategy::Single

      def new_role role
        role = role.kind_of?(Array) ? role.first : role
        role.to_s
      end

      def new_roles *roles
        new_role roles.flatten.first
      end
      
      def present_role role
        return role if role.kind_of? Array
        role.split(',').map(&:to_sym)
      end

      def set_empty_role
        self.send("#{role_attribute}=", "")
      end

      alias_method :present_roles, :present_role
    end

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


Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roles_data_mapper-0.3.1 lib/roles_data_mapper/strategy/single/role_string.rb
roles_data_mapper-0.3.0 lib/roles_data_mapper/strategy/single/role_string.rb
roles_data_mapper-0.2.2 lib/roles_data_mapper/strategy/single/role_string.rb
roles_data_mapper-0.2.1 lib/roles_data_mapper/strategy/single/role_string.rb
roles_data_mapper-0.2.0 lib/roles_data_mapper/strategy/single/role_string.rb