Sha256: 48b27de5cd6c53763f127a29ad91ba631dd36cf9c17c733e3f7b23f1a1520f46
Contents?: true
Size: 1.38 KB
Versions: 4
Compression:
Stored size: 1.38 KB
Contents
puts "AF" module RoleStrategy::DataMapper 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 all(role_attribute => :admin) else all(role_attribute => :default) end end end module Implementation def role_attribute strategy_class.roles_attribute_name end # assign roles def roles=(*new_roles) first_role = new_roles.flatten.first if valid_role?(first_role) value = first_role.admin? ? :admin : :default self.send("#{role_attribute}=", value) else raise ArgumentError, "The role #{first_role} is not a valid role" end end # query assigned roles def roles role = self.send(role_attribute).include?(:admin) ? strategy_class.admin_role_key : strategy_class.default_role_key [role] end alias_method :roles_list, :roles end # Implementation extend Roles::Generic::User::Configuration configure :num => :single end end
Version data entries
4 entries across 4 versions & 1 rubygems