Class: Decidim::ResourceLocatorPresenter

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/app/presenters/decidim/resource_locator_presenter.rb

Overview

A presenter to get the url or path from a resource. resource - a record or array of nested records.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ResourceLocatorPresenter

Returns a new instance of ResourceLocatorPresenter.



7
8
9
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 7

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



11
12
13
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 11

def resource
  @resource
end

Instance Method Details

#admin_index(options = {}) ⇒ Object

Builds the admin index path to the associated collection of resources

options - An optional hash of options to pass to the Rails router

Returns a String.



47
48
49
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 47

def admin_index(options = {})
  admin_collection_route("path", options)
end

#edit(options = {}) ⇒ Object

Builds the admin edit path to the resource.

options - An optional hash of options to pass to the Rails router

Returns a String.



67
68
69
70
71
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 67

def edit(options = {})
  options.merge!(options_for_polymorphic)

  admin_route_proxy.send("edit_#{member_route_name}_path", target, options)
end

#index(options = {}) ⇒ Object

Builds the index path to the associated collection of resources.

options - An optional hash of options to pass to the Rails router

Returns a String.



38
39
40
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 38

def index(options = {})
  collection_route("path", options)
end

#path(options = {}) ⇒ Object

Builds the path to the resource. Useful when linking to a resource from another engine.

options - An optional hash of options to pass to the Rails router

Returns a String.



19
20
21
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 19

def path(options = {})
  member_route("path", options)
end

#show(options = {}) ⇒ Object

Builds the admin show path to the resource.

options - An optional hash of options to pass to the Rails router

Returns a String.



56
57
58
59
60
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 56

def show(options = {})
  options.merge!(options_for_polymorphic)

  admin_route_proxy.send("#{member_route_name}_path", target, options)
end

#url(options = {}) ⇒ Object

Builds the url to the resource. Useful when linking to a resource from another engine.

options - An optional hash of options to pass to the Rails router

Returns a String.



29
30
31
# File 'decidim-core/app/presenters/decidim/resource_locator_presenter.rb', line 29

def url(options = {})
  member_route("url", options.merge(host: root_resource.organization.host))
end