Class: MerbResourceScope::Controller::Helpers::UrlGenerator
- Inherits:
-
Object
- Object
- MerbResourceScope::Controller::Helpers::UrlGenerator
- Defined in:
- lib/merb-resource-scope/controller/helpers.rb
Instance Attribute Summary collapse
-
#name_prefixes ⇒ Object
Returns the value of attribute name_prefixes.
-
#named_route ⇒ Object
Returns the value of attribute named_route.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#resources_with_specs ⇒ Object
Returns the value of attribute resources_with_specs.
Instance Method Summary collapse
-
#add(*args) ⇒ Object
(also: #with)
this is so we can extend out current name_route will be used in congunction of the url helpers enclosing_resource_url{|route| route.add(:comments)}.
- #generate_named_route ⇒ Object
-
#initialize(name_prefixes, resources_with_specs) {|_self| ... } ⇒ UrlGenerator
constructor
A new instance of UrlGenerator.
Constructor Details
#initialize(name_prefixes, resources_with_specs) {|_self| ... } ⇒ UrlGenerator
Returns a new instance of UrlGenerator.
8 9 10 11 12 13 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 8 def initialize(name_prefixes, resources_with_specs, &block) @resources = [] @name_prefixes, @resources_with_specs = name_prefixes, resources_with_specs yield self if block_given? @named_route = generate_named_route end |
Instance Attribute Details
#name_prefixes ⇒ Object
Returns the value of attribute name_prefixes.
6 7 8 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 6 def name_prefixes @name_prefixes end |
#named_route ⇒ Object
Returns the value of attribute named_route.
6 7 8 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 6 def named_route @named_route end |
#resources ⇒ Object
Returns the value of attribute resources.
6 7 8 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 6 def resources @resources end |
#resources_with_specs ⇒ Object
Returns the value of attribute resources_with_specs.
6 7 8 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 6 def resources_with_specs @resources_with_specs end |
Instance Method Details
#add(*args) ⇒ Object Also known as: with
this is so we can extend out current name_route will be used in congunction of the url helpers enclosing_resource_url{|route| route.add(:comments)}
is a symbol of the named_route you want to add, so lets
say we had enclosing_resource_url of /users/1/
and we wanted to add tags on to this url we can simple
enclosing_resource_url{|route| route.add(:tags)}
and this will be /users/1/tags
You can also add custom routes as well then as well
add(:tags, :pending)
Also add a resource as well, add(:tag, @tag)
Also do a new this way as well add(:tag, :new)
And finally add(:tag, :edit, @tag) Where the @tag
has to be the last option
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 38 def add(*args) name_prefixes.flatten! name_prefixes << args.shift args.each do |arg| if arg.is_a?(Symbol) name_prefixes.unshift(arg.to_s) else resources << arg end end self end |
#generate_named_route ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/merb-resource-scope/controller/helpers.rb', line 53 def generate_named_route if resources_with_specs none_singletons = resources_with_specs.reject{|rs| rs[1].singleton} resources << none_singletons.map{|rs| rs[0]} end generated_named_route = name_prefixes.flatten.compact.join('_').intern end |