Class: Decidim::ResourceLocatorPresenter

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

Overview

A presenter to get the url or path from a resource.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ResourceLocatorPresenter

Returns a new instance of ResourceLocatorPresenter.



6
7
8
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 6

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 10

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.



46
47
48
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 46

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.



64
65
66
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 64

def edit(options = {})
  admin_route_proxy.send("edit_#{member_route_name}_path", resource, 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.



37
38
39
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 37

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.



18
19
20
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 18

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.



55
56
57
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 55

def show(options = {})
  admin_route_proxy.send("#{member_route_name}_path", resource, 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.



28
29
30
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 28

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