Module: HalApi::Representer::CollectionPaging
- Extended by:
- ActiveSupport::Concern
- Included in:
- PagedCollectionRepresenter
- Defined in:
- lib/hal_api/representer/collection_paging.rb
Instance Method Summary collapse
-
#href_url_helper(options = {}) ⇒ Object
refactor to use single property, :url, that can be a method name, a string, or a lambda if it is a method name, execute against self - the representer - which has local url helpers methods if it is a sym/string, but self does not respond to it, then just use that string if it is a lambda, execute in the context against the represented.parent (if there is one) or represented.
- #params ⇒ Object
- #profile_url(represented) ⇒ Object
- #represented_url ⇒ Object
- #self_url(represented) ⇒ Object
Instance Method Details
#href_url_helper(options = {}) ⇒ Object
refactor to use single property, :url, that can be a method name, a string, or a lambda if it is a method name, execute against self - the representer - which has local url helpers methods if it is a sym/string, but self does not respond to it, then just use that string if it is a lambda, execute in the context against the represented.parent (if there is one) or represented
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hal_api/representer/collection_paging.rb', line 47 def href_url_helper(={}) if represented_url.nil? = .except(:format) result = url_for(.merge(only_path: true)) rescue nil if represented.parent result ||= polymorphic_path([:api, represented.parent, represented.item_class], ) rescue nil end result ||= polymorphic_path([:api, represented.item_class], ) rescue nil return result end if represented_url.respond_to?(:call) self.instance_exec(, &represented_url) elsif self.respond_to?(represented_url) self.send(represented_url, ) else represented_url.to_s end end |
#params ⇒ Object
31 32 33 |
# File 'lib/hal_api/representer/collection_paging.rb', line 31 def params represented.params end |
#profile_url(represented) ⇒ Object
39 40 41 |
# File 'lib/hal_api/representer/collection_paging.rb', line 39 def profile_url(represented) model_uri(:collection, represented.item_class) end |
#represented_url ⇒ Object
67 68 69 |
# File 'lib/hal_api/representer/collection_paging.rb', line 67 def represented_url @represented_url ||= represented.try(:url) end |
#self_url(represented) ⇒ Object
35 36 37 |
# File 'lib/hal_api/representer/collection_paging.rb', line 35 def self_url(represented) href_url_helper(represented.params) end |