Class: Lockdown::Resource
- Inherits:
-
Object
- Object
- Lockdown::Resource
- Defined in:
- lib/lockdown/resource.rb
Class Attribute Summary collapse
-
.resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
The only methods restricted on the resource.
-
#inclusions ⇒ Object
The only methods allowed on the resource.
-
#name ⇒ Object
Name of the resource.
-
#regex_pattern ⇒ Object
Regular expression pattern.
Class Method Summary collapse
-
.all_access ⇒ String
All registered regular expressions joined by a pipe.
-
.register_regex(resource) ⇒ Object
When a new resource is created, this method is called to register the root.
-
.reset_resources ⇒ Object
Reset resources to empty array.
Instance Method Summary collapse
- #except(*methods) ⇒ Object
-
#initialize(name) ⇒ Resource
constructor
A new instance of Resource.
- #only(*methods) ⇒ Object
Constructor Details
#initialize(name) ⇒ Resource
Returns a new instance of Resource.
39 40 41 42 43 |
# File 'lib/lockdown/resource.rb', line 39 def initialize(name) @name = name.to_s @regex_pattern = "\/#{@name}(\/.*)?" self.class.register_regex(@regex_pattern) end |
Class Attribute Details
.resources ⇒ Object (readonly)
Returns the value of attribute resources.
6 7 8 |
# File 'lib/lockdown/resource.rb', line 6 def resources @resources end |
Instance Attribute Details
#exceptions ⇒ Object
The only methods restricted on the resource
33 34 35 |
# File 'lib/lockdown/resource.rb', line 33 def exceptions @exceptions end |
#inclusions ⇒ Object
The only methods allowed on the resource
35 36 37 |
# File 'lib/lockdown/resource.rb', line 35 def inclusions @inclusions end |
#name ⇒ Object
Name of the resource
29 30 31 |
# File 'lib/lockdown/resource.rb', line 29 def name @name end |
#regex_pattern ⇒ Object
Regular expression pattern
31 32 33 |
# File 'lib/lockdown/resource.rb', line 31 def regex_pattern @regex_pattern end |
Class Method Details
.all_access ⇒ String
Returns all registered regular expressions joined by a pipe.
15 16 17 |
# File 'lib/lockdown/resource.rb', line 15 def all_access @resources.join(Lockdown::DELIMITER) end |
.register_regex(resource) ⇒ Object
When a new resource is created, this method is called to register the root
9 10 11 12 |
# File 'lib/lockdown/resource.rb', line 9 def register_regex(resource) resource = "(#{resource})" @resources << resource unless @resources.include?(resource) end |
.reset_resources ⇒ Object
Reset resources to empty array
20 21 22 |
# File 'lib/lockdown/resource.rb', line 20 def reset_resources @resources = [] end |
Instance Method Details
#except(*methods) ⇒ Object
46 47 48 49 50 |
# File 'lib/lockdown/resource.rb', line 46 def except(*methods) return if methods.empty? @exceptions = methods.collect{|m| m.to_s} @regex_pattern = "\/#{@name}(?!\/(#{@exceptions.join('|')}))(\/.*)?" end |
#only(*methods) ⇒ Object
53 54 55 56 57 |
# File 'lib/lockdown/resource.rb', line 53 def only(*methods) return if methods.empty? @inclusions = methods.collect{|m| m.to_s} @regex_pattern = "\/#{@name}\/(#{@inclusions.join('|')})(\/)?" end |