Module: Puffer::Resource::Routing

Includes:
ActionController::UrlFor
Included in:
Puffer::Resource
Defined in:
lib/puffer/resource/routing.rb

Instance Method Summary collapse

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, options = {}
  send url_method_name(routing_type, url_segment, options.delete(:action)), *url_arguments, options
end

#default_url_options(*args) ⇒ Object



42
43
44
# File 'lib/puffer/resource/routing.rb', line 42

def default_url_options *args
  Puffer::Base.default_url_options(*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
  options = args.extract_options!
  member_method routing_type, *args, options.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
  options = args.extract_options!
  send url_method_name(routing_type, singular, options.delete(:action)), *url_arguments(use_resource_id(args.first) || member_id), options
end

#new_method(routing_type, options = {}) ⇒ Object



17
18
19
# File 'lib/puffer/resource/routing.rb', line 17

def new_method routing_type, options = {}
  send url_method_name(routing_type, singular, :new), *url_arguments, options
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