Class: Shark::Permissions::Resource
- Inherits:
-
Object
- Object
- Shark::Permissions::Resource
- Defined in:
- lib/shark/permissions/resource.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #ancestors_and_self ⇒ Object
-
#initialize(value) ⇒ Resource
constructor
A new instance of Resource.
- #parent ⇒ Object
- #subresource_of?(value) ⇒ Boolean
- #super_resource_of?(value) ⇒ Boolean
- #to_s ⇒ Object
- #wildcard? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Resource
Returns a new instance of Resource.
8 9 10 11 12 13 14 15 16 |
# File 'lib/shark/permissions/resource.rb', line 8 def initialize(value) @name = case value when String value when Array value.map(&:to_s).join(Shark::Permissions.delimiter) end @parts = @name.split(Shark::Permissions.delimiter) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/shark/permissions/resource.rb', line 6 def name @name end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
6 7 8 |
# File 'lib/shark/permissions/resource.rb', line 6 def parts @parts end |
Instance Method Details
#ancestors ⇒ Object
27 28 29 |
# File 'lib/shark/permissions/resource.rb', line 27 def ancestors ancestors_and_self[0..-2] end |
#ancestors_and_self ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/shark/permissions/resource.rb', line 18 def ancestors_and_self names = [] parts.each_with_index do |_, i| names << parts[0..i].join(Shark::Permissions.delimiter) end names end |
#parent ⇒ Object
31 32 33 34 |
# File 'lib/shark/permissions/resource.rb', line 31 def parent parent_name = parts[0..-2].join(Shark::Permissions.delimiter) parent_name.presence end |
#subresource_of?(value) ⇒ Boolean
36 37 38 39 40 41 |
# File 'lib/shark/permissions/resource.rb', line 36 def subresource_of?(value) return true if name == value regexp = value.gsub('*', '[a-z\-_0-9]*') "#{name}::".match(/\A#{regexp}::/).present? end |
#super_resource_of?(value) ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/shark/permissions/resource.rb', line 43 def super_resource_of?(value) return true if name == value regexp = name.gsub('*', '[a-z\-_0-9]*') "#{value}::".match(/\A#{regexp}::/).present? end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/shark/permissions/resource.rb', line 54 def to_s name end |
#wildcard? ⇒ Boolean
50 51 52 |
# File 'lib/shark/permissions/resource.rb', line 50 def wildcard? parts.last == Shark::Permissions.any_matcher end |