Class: Decidim::ResourceLocatorPresenter
- Inherits:
-
Object
- Object
- Decidim::ResourceLocatorPresenter
- Defined in:
- 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
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#admin_index(options = {}) ⇒ Object
Builds the admin index path to the associated collection of resources.
-
#edit(options = {}) ⇒ Object
Builds the admin edit path to the resource.
-
#index(options = {}) ⇒ Object
Builds the index path to the associated collection of resources.
-
#initialize(resource) ⇒ ResourceLocatorPresenter
constructor
A new instance of ResourceLocatorPresenter.
-
#path(options = {}) ⇒ Object
Builds the path to the resource.
-
#show(options = {}) ⇒ Object
Builds the admin show path to the resource.
-
#url(options = {}) ⇒ Object
Builds the url to the resource.
Constructor Details
#initialize(resource) ⇒ ResourceLocatorPresenter
Returns a new instance of ResourceLocatorPresenter.
7 8 9 |
# File 'app/presenters/decidim/resource_locator_presenter.rb', line 7 def initialize(resource) @resource = resource end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
11 12 13 |
# File '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 'app/presenters/decidim/resource_locator_presenter.rb', line 47 def admin_index( = {}) admin_collection_route("path", ) 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 'app/presenters/decidim/resource_locator_presenter.rb', line 67 def edit( = {}) .merge!() admin_route_proxy.send("edit_#{member_route_name}_path", target, ) 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 'app/presenters/decidim/resource_locator_presenter.rb', line 38 def index( = {}) collection_route("path", ) 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 'app/presenters/decidim/resource_locator_presenter.rb', line 19 def path( = {}) member_route("path", ) 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 'app/presenters/decidim/resource_locator_presenter.rb', line 56 def show( = {}) .merge!() admin_route_proxy.send("#{member_route_name}_path", target, ) 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 'app/presenters/decidim/resource_locator_presenter.rb', line 29 def url( = {}) member_route("url", .merge(host: root_resource.organization.host)) end |