lib/jsonapi/resource.rb in jsonapi-resources-0.9.0 vs lib/jsonapi/resource.rb in jsonapi-resources-0.9.1.beta1
- old
+ new
@@ -451,11 +451,11 @@
end
end
def resource_for(type)
type = type.underscore
- type_with_module = type.include?('/') ? type : module_path + type
+ type_with_module = type.start_with?(module_path) ? type : module_path + type
resource_name = _resource_name_from_type(type_with_module)
resource = resource_name.safe_constantize if resource_name
if resource.nil?
fail NameError, "JSONAPI: Could not find resource '#{type}'. (Class #{resource_name} not found)"
@@ -505,14 +505,16 @@
attrs.each do |attr|
attribute(attr, options)
end
end
- def attribute(attr, options = {})
+ def attribute(attribute_name, options = {})
+ attr = attribute_name.to_sym
+
check_reserved_attribute_name(attr)
- if (attr.to_sym == :id) && (options[:format].nil?)
+ if (attr == :id) && (options[:format].nil?)
ActiveSupport::Deprecation.warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.')
end
check_duplicate_attribute_name(attr) if options[:format].nil?
@@ -806,10 +808,13 @@
_model_class.all
end
def verify_filters(filters, context = nil)
verified_filters = {}
+
+ return verified_filters if filters.nil?
+
filters.each do |filter, raw_value|
verified_filter = verify_filter(filter, raw_value, context)
verified_filters[verified_filter[0]] = verified_filter[1]
end
verified_filters
@@ -1036,10 +1041,11 @@
def _add_relationship(klass, *attrs)
options = attrs.extract_options!
options[:parent_resource] = self
- attrs.each do |relationship_name|
+ attrs.each do |name|
+ relationship_name = name.to_sym
check_reserved_relationship_name(relationship_name)
check_duplicate_relationship_name(relationship_name)
JSONAPI::RelationshipBuilder.new(klass, _model_class, options)
.define_relationship_methods(relationship_name.to_sym)