Sha256: f84b24668578d12b16613e5d76df858c57d928b781824e204d5f39aff43463f5

Contents?: true

Size: 1012 Bytes

Versions: 6

Compression:

Stored size: 1012 Bytes

Contents

module Roles::Generic::User
  module ClassMethods
    def inherited(subclass) # :nodoc:
      ::Roles::Generic::User::INHERITABLE_CLASS_ATTRIBUTES.each do |attribute|
        instance_var = "@#{attribute}"
        subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
      end
      super
    end
    
    # set the bitmask attribute role assignments will be stored in
    def roles_attribute(name)
      self.roles_attribute = name
    end

    # alternative method signature: set the bitmask attribute role assignments will be stored in
    def roles_attribute=(name)
      self.roles_attribute_name = name.to_sym
    end

    # :call-seq:
    #   roles(:role_1, ..., :role_n)
    #   roles('role_1', ..., 'role_n')
    #   roles([:role_1, ..., :role_n])
    #   roles(['role_1', ..., 'role_n'])
    #
    # declare valid roles
    def roles(*roles) 
      puts "role_class: #{role_class_name}"
      self.valid_roles = Array[*roles].flatten.map { |r| r.to_sym }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
roles_generic-0.2.6 lib/roles_generic/generic/user/class_methods.rb
roles_generic-0.2.5 lib/roles_generic/generic/user/class_methods.rb
roles_generic-0.2.4 lib/roles_generic/generic/user/class_methods.rb
roles_generic-0.2.3 lib/roles_generic/generic/user/class_methods.rb
roles_generic-0.2.2 lib/roles_generic/generic/user/class_methods.rb
roles_generic-0.2.1 lib/roles_generic/generic/user/class_methods.rb