Class: Roleback::Definitions::Resource
- Defined in:
- lib/roleback/definitions/resource.rb
Constant Summary collapse
- DEFAULT_ACTION_PATH =
[:create, :show, :update, :destroy, :index, :new, :edit]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from RuleBased
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, role:, scope: ::Roleback::ANY, options: {}, &block) ⇒ Resource
constructor
A new instance of Resource.
- #match(resource) ⇒ Object
Methods inherited from RuleBased
Constructor Details
#initialize(name, role:, scope: ::Roleback::ANY, options: {}, &block) ⇒ Resource
Returns a new instance of Resource.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/roleback/definitions/resource.rb', line 8 def initialize(name, role:, scope: ::Roleback::ANY, options: {}, &block) @name = name @role = role @scope = scope = super(role: role, resource: self, scope: scope) # create rules for each action selected_actions.each do |action| do_rule(role: @role, resource: self, scope: @scope, action: action, outcome: ::Roleback::ALLOW) end instance_eval(&block) if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/roleback/definitions/resource.rb', line 4 def name @name end |
Instance Method Details
#==(other) ⇒ Object
31 32 33 34 35 |
# File 'lib/roleback/definitions/resource.rb', line 31 def ==(other) return false unless other.respond_to?(:name) other.name == name end |
#match(resource) ⇒ Object
26 27 28 29 |
# File 'lib/roleback/definitions/resource.rb', line 26 def match(resource) to_check = resource.is_a?(::Roleback::Definitions::Resource) ? resource.name.to_s : resource.to_s @name.to_s == to_check || @name == ::Roleback.any || resource == ::Roleback.any end |