lib/jsonapi/routing_ext.rb in jsonapi-resources-0.4.0 vs lib/jsonapi/routing_ext.rb in jsonapi-resources-0.4.1

- old
+ new

@@ -24,10 +24,17 @@ options = resources.extract_options!.dup options[:controller] ||= @resource_type options.merge!(res.routing_resource_options) options[:path] = format_route(@resource_type) + if options[:except] + options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + else + options[:except] = [:new, :edit] + end + resource @resource_type, options do @scope[:jsonapi_resource] = @resource_type if block_given? yield @@ -35,19 +42,19 @@ jsonapi_relationships end end end - def jsonapi_relationships + def jsonapi_relationships(options = {}) res = JSONAPI::Resource.resource_for(resource_type_with_module_prefix(@resource_type)) res._associations.each do |association_name, association| if association.is_a?(JSONAPI::Association::HasMany) - jsonapi_links(association_name) - jsonapi_related_resources(association_name) + jsonapi_links(association_name, options) + jsonapi_related_resources(association_name, options) else - jsonapi_link(association_name) - jsonapi_related_resource(association_name) + jsonapi_link(association_name, options) + jsonapi_related_resource(association_name, options) end end end def jsonapi_resources(*resources, &block) @@ -59,9 +66,16 @@ options.merge!(res.routing_resource_options) options[:param] = :id options[:path] = format_route(@resource_type) + + if options[:except] + options[:except] << :new unless options[:except].include?(:new) || options[:except].include?('new') + options[:except] << :edit unless options[:except].include?(:edit) || options[:except].include?('edit') + else + options[:except] = [:new, :edit] + end resources @resource_type, options do @scope[:jsonapi_resource] = @resource_type if block_given?