Class: Monty::Resource
- Inherits:
-
Object
- Object
- Monty::Resource
- Defined in:
- lib/monty/resource.rb
Class Attribute Summary collapse
-
.resources ⇒ Object
Returns the value of attribute resources.
-
.resources_regex ⇒ Object
Returns the value of attribute resources_regex.
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
-
.regex ⇒ Regexp
Created from resources’ base regex.
-
.register_regex(resource) ⇒ Object
When a new resource is created, this method is called to register the root.
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.
34 35 36 37 38 |
# File 'lib/monty/resource.rb', line 34 def initialize(name) @name = name.to_s @regex_pattern = "\/#{@name}(\/.*)?" self.class.register_regex(@regex_pattern) end |
Class Attribute Details
.resources ⇒ Object
Returns the value of attribute resources.
6 7 8 |
# File 'lib/monty/resource.rb', line 6 def resources @resources end |
.resources_regex ⇒ Object
Returns the value of attribute resources_regex.
6 7 8 |
# File 'lib/monty/resource.rb', line 6 def resources_regex @resources_regex end |
Instance Attribute Details
#exceptions ⇒ Object
The only methods restricted on the resource
28 29 30 |
# File 'lib/monty/resource.rb', line 28 def exceptions @exceptions end |
#inclusions ⇒ Object
The only methods allowed on the resource
30 31 32 |
# File 'lib/monty/resource.rb', line 30 def inclusions @inclusions end |
#name ⇒ Object
Name of the resource
24 25 26 |
# File 'lib/monty/resource.rb', line 24 def name @name end |
#regex_pattern ⇒ Object
Regular expression pattern
26 27 28 |
# File 'lib/monty/resource.rb', line 26 def regex_pattern @regex_pattern end |
Class Method Details
.regex ⇒ Regexp
Returns created from resources’ base regex.
15 16 17 |
# File 'lib/monty/resource.rb', line 15 def regex @resources_regex ||= Monty.regex(@resources.join("|")) 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/monty/resource.rb', line 9 def register_regex(resource) resource = "(#{resource})" @resources << resource unless @resources.include?(resource) end |
Instance Method Details
#except(*methods) ⇒ Object
41 42 43 44 45 |
# File 'lib/monty/resource.rb', line 41 def except(*methods) return if methods.empty? @exceptions = methods.collect{|m| m.to_s} @regex_pattern = "\/#{@name}(?!\/(#{@exceptions.join('|')}))(\/.*)?" end |
#only(*methods) ⇒ Object
48 49 50 51 52 |
# File 'lib/monty/resource.rb', line 48 def only(*methods) return if methods.empty? @inclusions = methods.collect{|m| m.to_s} @regex_pattern = "\/#{@name}\/(#{@inclusions.join('|')})(\/)?" end |