Class: NonGrata::Privilege

Inherits:
Object
  • Object
show all
Defined in:
lib/non_grata/privilege.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, resource) ⇒ Privilege

Returns a new instance of Privilege.



7
8
9
10
# File 'lib/non_grata/privilege.rb', line 7

def initialize(action, resource)
    self.resource = resource
    self.action = action
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/non_grata/privilege.rb', line 5

def action
  @action
end

#resourceObject

Returns the value of attribute resource.



4
5
6
# File 'lib/non_grata/privilege.rb', line 4

def resource
  @resource
end

Instance Method Details

#applies_to?(resource_obj) ⇒ Boolean

APPLIES_TO? @params:

resource - an resource to test if the privilege applies to

Will determen if the privilege applies to the given passed resource. This resourceect can be a class type, class instance, or a string.

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/non_grata/privilege.rb', line 44

def applies_to?(resource_obj)
    resource_sym = nil
    case resource_obj
    when String
        resource_sym = resource_obj.underscore.to_sym
    when Symbol
        resource_sym = resource_obj
    when Class
        resource_sym = resource_obj.name.underscore.to_sym 
    else 
        resource_sym = resource_obj.class.name.underscore.to_sym
    end

    return (resource_sym == @resource)
end