Class: Roleback::Definitions::Scope

Inherits:
RuleBased
  • Object
show all
Defined in:
lib/roleback/definitions/scope.rb

Instance Attribute Summary collapse

Attributes inherited from RuleBased

#role

Instance Method Summary collapse

Methods inherited from RuleBased

#<=>, #can, #cannot

Constructor Details

#initialize(name, role:, options: {}, &block) ⇒ Scope

Returns a new instance of Scope.



6
7
8
9
10
11
12
13
14
# File 'lib/roleback/definitions/scope.rb', line 6

def initialize(name, role:, options: {}, &block)
	@name = name
	@role = role
	@options = options

	super(role: role, scope: self, resource: ::Roleback::ANY)

	instance_eval(&block) if block_given?
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/roleback/definitions/scope.rb', line 4

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
28
29
# File 'lib/roleback/definitions/scope.rb', line 25

def ==(other)
	return false unless other.respond_to?(:name)

	other.name == name
end

#match(scope) ⇒ Object



20
21
22
23
# File 'lib/roleback/definitions/scope.rb', line 20

def match(scope)
	to_check = scope.is_a?(::Roleback::Definitions::Scope) ? scope.name.to_s : scope.to_s
	@name.to_s == scope.name.to_s || @name == ::Roleback.any || scope == ::Roleback.any
end

#resource(name, options = {}, &block) ⇒ Object



16
17
18
# File 'lib/roleback/definitions/scope.rb', line 16

def resource(name, options = {}, &block)
	::Roleback::Definitions::Resource.new(name, role: @role, scope: self, options: options, &block)
end