class NonGrata::Scheme

Attributes

style[RW]
tenantable[RW]

Public Class Methods

new(scheme_name='main', options={}) click to toggle source
# File lib/non_grata/scheme.rb, line 4
def  initialize(scheme_name='main', options={})
    @name = scheme_name 
    self.style  = :declaritive

    options.each do |k,v| 
        send("#{k.to_s}=",v) if self.respond_to?("#{k}=")
    end
end

Public Instance Methods

config(&block) click to toggle source

called by the configuration DSL in order to parse a scheme block.

example:

scheme.config do 
    role :user do 
        privilege :site, :login
    end
end
# File lib/non_grata/scheme.rb, line 79
def config(&block)
    instance_eval(&block)
end
is_declaritive?() click to toggle source
# File lib/non_grata/scheme.rb, line 12
def is_declaritive?
    self.style == :declaritive
end
is_dynamic?() click to toggle source
# File lib/non_grata/scheme.rb, line 15
def is_dynamic?
    self.style == :db
end
name() click to toggle source
# File lib/non_grata/scheme.rb, line 25
def name
    @name
end
name=(value) click to toggle source
# File lib/non_grata/scheme.rb, line 29
def name=(value)
    @name = value.to_sym
end
privilege(resource, name) click to toggle source

this function is used by the configuration DSL and should not be called directly. adds a new privilege to the scheme

# File lib/non_grata/scheme.rb, line 51
def privilege(resource, name)
    if self.style == :declaritive 
        raise "Can not set privileges on a declaritive scheme. Privileges must be inside a role."
    end
    privileges << Privilege.new(resource, name)
end
privileges() click to toggle source

returns a list of privileges for this scheme

# File lib/non_grata/scheme.rb, line 21
def privileges
    @privileges ||= []
end
role(name, &block) click to toggle source

this function is used by the configuration DSL and should not be called directly. It is used to add a new role to the scheme

# File lib/non_grata/scheme.rb, line 63
def role(name, &block)
    r = Role.new(name)
    r.config(&block)
    roles << r
end
roles(role_name = nil) click to toggle source

returns a list of roles for this scheme or returns a specific role by name Ex:

scheme.roles  <- returns an array of all roles
scheme.roles(:user)  <- returns the user role
# File lib/non_grata/scheme.rb, line 40
def roles(role_name = nil)
    @roles ||= []
    return @roles if role_name.nil?
    return @roles.find{|i| i.name == role_name} 
end