lib/jsonapi/routing_ext.rb in jsonapi-resources-0.0.16 vs lib/jsonapi/routing_ext.rb in jsonapi-resources-0.1.0

- old
+ new

@@ -17,11 +17,11 @@ JSONAPI.configuration.route_formatter.format(route.to_s) end def jsonapi_resource(*resources, &block) resource_type = resources.first - res = JSONAPI::Resource.resource_for(resource_type) + res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(resources.first)) options = resources.extract_options!.dup options[:controller] ||= resource_type options.merge!(res.routing_resource_options) options[:path] = format_route(resource_type) @@ -43,15 +43,11 @@ end end def jsonapi_resources(*resources, &block) resource_type = resources.first - resource_type_with_module_prefix = [ - @scope[:module], - resource_type - ].compact.collect(&:to_s).join("/") - res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix) + res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(resources.first)) options = resources.extract_options!.dup options[:controller] ||= resource_type options.merge!(res.routing_resource_options) @@ -91,62 +87,67 @@ def jsonapi_link(*links) link_type = links.first formatted_association_name = format_route(link_type) options = links.extract_options!.dup - res = JSONAPI::Resource.resource_for(@scope[:jsonapi_resource]) + res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix) methods = links_methods(options) if methods.include?(:show) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'show_association', association: link_type.to_s, via: [:get] + action: 'show_association', association: link_type.to_s, via: [:get] end if methods.include?(:create) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'create_association', association: link_type.to_s, via: [:post] + action: 'create_association', association: link_type.to_s, via: [:post] end if methods.include?(:update) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'update_association', association: link_type.to_s, via: [:put] + action: 'update_association', association: link_type.to_s, via: [:put] end if methods.include?(:destroy) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'destroy_association', association: link_type.to_s, via: [:delete] + action: 'destroy_association', association: link_type.to_s, via: [:delete] end end def jsonapi_links(*links) link_type = links.first formatted_association_name = format_route(link_type) options = links.extract_options!.dup - res = JSONAPI::Resource.resource_for(@scope[:jsonapi_resource]) + res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix) methods = links_methods(options) if methods.include?(:show) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'show_association', association: link_type.to_s, via: [:get] + action: 'show_association', association: link_type.to_s, via: [:get] end if methods.include?(:create) match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'create_association', association: link_type.to_s, via: [:post] + action: 'create_association', association: link_type.to_s, via: [:post] end if methods.include?(:update) && res._association(link_type).acts_as_set match "links/#{formatted_association_name}", controller: res._type.to_s, - action: 'update_association', association: link_type.to_s, via: [:put] + action: 'update_association', association: link_type.to_s, via: [:put] end if methods.include?(:destroy) match "links/#{formatted_association_name}/:keys", controller: res._type.to_s, - action: 'destroy_association', association: link_type.to_s, via: [:delete] + action: 'destroy_association', association: link_type.to_s, via: [:delete] end + end + + def resource_type_with_module_prefix(resource = nil) + resource_name = resource || @scope[:jsonapi_resource] + [@scope[:module], resource_name].compact.collect(&:to_s).join("/") end end end end end