Class: Resource
- Inherits:
-
Object
- Object
- Resource
- Defined in:
- lib/whales_dispatch/resource.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #build_base(parent) ⇒ Object
- #build_route_pattern(suffix, parent) ⇒ Object
- #classify ⇒ Object
-
#initialize(noun, suffix, parent) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(noun, suffix, parent) ⇒ Resource
Returns a new instance of Resource.
4 5 6 7 |
# File 'lib/whales_dispatch/resource.rb', line 4 def initialize(noun, suffix, parent) @noun = noun.to_s @pattern = build_route_pattern(suffix, parent) end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
2 3 4 |
# File 'lib/whales_dispatch/resource.rb', line 2 def pattern @pattern end |
Instance Method Details
#build_base(parent) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/whales_dispatch/resource.rb', line 14 def build_base(parent) if parent.empty? "^/" else "^/#{parent}/(?<#{parent.singularize}_id>\\d+)/" end end |
#build_route_pattern(suffix, parent) ⇒ Object
9 10 11 12 |
# File 'lib/whales_dispatch/resource.rb', line 9 def build_route_pattern(suffix, parent) base = build_base(parent) Regexp.new(base + @noun + suffix) end |
#classify ⇒ Object
22 23 24 |
# File 'lib/whales_dispatch/resource.rb', line 22 def classify klass = Object.const_get(@noun.capitalize + "Controller") end |