Class: ResourceFull::Models::ResourcedRoute
- Inherits:
-
Object
- Object
- ResourceFull::Models::ResourcedRoute
- Defined in:
- lib/resource_full/models/resourced_route.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
- .find(what, opts = {}) ⇒ Object
- .find_all_routes(opts = {}) ⇒ Object
- .find_named_route(name) ⇒ Object
Instance Method Summary collapse
- #formatted? ⇒ Boolean
-
#initialize(opts = {}) ⇒ ResourcedRoute
constructor
A new instance of ResourcedRoute.
- #resource ⇒ Object
- #resourced? ⇒ Boolean
- #to_xml(opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ResourcedRoute
Returns a new instance of ResourcedRoute.
52 53 54 55 56 57 58 |
# File 'lib/resource_full/models/resourced_route.rb', line 52 def initialize(opts={}) @verb = opts[:verb] @name = opts[:name] @pattern = opts[:pattern] @action = opts[:action] @controller = ResourceFull::Base.controller_for(opts[:controller]) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/resource_full/models/resourced_route.rb', line 7 def action @action end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
7 8 9 |
# File 'lib/resource_full/models/resourced_route.rb', line 7 def controller @controller end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/resource_full/models/resourced_route.rb', line 7 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
7 8 9 |
# File 'lib/resource_full/models/resourced_route.rb', line 7 def pattern @pattern end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
7 8 9 |
# File 'lib/resource_full/models/resourced_route.rb', line 7 def verb @verb end |
Class Method Details
.find(what, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/resource_full/models/resourced_route.rb', line 10 def find(what, opts={}) case what when :all find_all_routes(opts) else find_named_route(what) end end |
.find_all_routes(opts = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/resource_full/models/resourced_route.rb', line 23 def find_all_routes(opts={}) all_named_routes(opts).reject do |route| opts.has_key?(:resource_id) && opts[:resource_id].to_s != route.resource.to_s end.sort_by {|r| r.name.to_s} end |
.find_named_route(name) ⇒ Object
19 20 21 |
# File 'lib/resource_full/models/resourced_route.rb', line 19 def find_named_route(name) all_named_routes.find {|route| route.name == name} or raise ResourceFull::Models::RouteNotFound, "Could not find route #{name}" end |
Instance Method Details
#formatted? ⇒ Boolean
70 71 72 |
# File 'lib/resource_full/models/resourced_route.rb', line 70 def formatted? name.to_s =~ /^formatted/ end |
#resource ⇒ Object
74 75 76 |
# File 'lib/resource_full/models/resourced_route.rb', line 74 def resource controller.controller_name end |
#resourced? ⇒ Boolean
78 79 80 |
# File 'lib/resource_full/models/resourced_route.rb', line 78 def resourced? controller.ancestors.include?(ResourceFull::Base) end |
#to_xml(opts = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/resource_full/models/resourced_route.rb', line 60 def to_xml(opts={}) { :resource => resource, :verb => verb, :name => name, :pattern => pattern, :action => action }.to_xml(opts.merge(:root => "route")) end |