Module: Puffer::Resource::Routing
- Includes:
- ActionController::UrlFor
- Included in:
- Puffer::Resource
- Defined in:
- lib/puffer/resource/routing.rb
Instance Method Summary collapse
- #collection_method(routing_type, options = {}) ⇒ Object
- #default_url_options(*args) ⇒ Object
- #edit_method(routing_type, *args) ⇒ Object
- #member_method(routing_type, *args) ⇒ Object
- #new_method(routing_type, options = {}) ⇒ Object
- #url_arguments(current = nil) ⇒ Object
- #url_method_name(routing_type, current, action = nil) ⇒ Object
- #use_resource_id(resource) ⇒ Object
Instance Method Details
#collection_method(routing_type, options = {}) ⇒ Object
8 9 10 |
# File 'lib/puffer/resource/routing.rb', line 8 def collection_method routing_type, = {} send url_method_name(routing_type, url_segment, .delete(:action)), *url_arguments, end |
#default_url_options(*args) ⇒ Object
42 43 44 |
# File 'lib/puffer/resource/routing.rb', line 42 def *args Puffer::Base.(*args) end |
#edit_method(routing_type, *args) ⇒ Object
21 22 23 24 |
# File 'lib/puffer/resource/routing.rb', line 21 def edit_method routing_type, *args = args. member_method routing_type, *args, .merge(:action => :edit) end |
#member_method(routing_type, *args) ⇒ Object
12 13 14 15 |
# File 'lib/puffer/resource/routing.rb', line 12 def member_method routing_type, *args = args. send url_method_name(routing_type, singular, .delete(:action)), *url_arguments(use_resource_id(args.first) || member_id), end |
#new_method(routing_type, options = {}) ⇒ Object
17 18 19 |
# File 'lib/puffer/resource/routing.rb', line 17 def new_method routing_type, = {} send url_method_name(routing_type, singular, :new), *url_arguments, end |
#url_arguments(current = nil) ⇒ Object
30 31 32 |
# File 'lib/puffer/resource/routing.rb', line 30 def url_arguments current = nil ancestors.map(&:member_id).push(current).compact end |
#url_method_name(routing_type, current, action = nil) ⇒ Object
26 27 28 |
# File 'lib/puffer/resource/routing.rb', line 26 def url_method_name routing_type, current, action = nil [action, scope, *ancestors.map(&:singular), current, routing_type].compact.join('_') end |
#use_resource_id(resource) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/puffer/resource/routing.rb', line 46 def use_resource_id(resource) if resource and resource.respond_to?(:id) resource.id else resource end end |