File tree Expand file tree Collapse file tree 4 files changed +18
-9
lines changed Expand file tree Collapse file tree 4 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 1
1
language : ruby
2
2
rvm :
3
+ - 1.9.3
3
4
- 2.0.0
4
- - 2.1.1
5
+ - 2.1
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def initialize(params = nil, options = {})
20
20
end
21
21
22
22
def setup ( params )
23
- @resource_klass ||= self . class . resource_for ( params [ :controller ] ) if params [ :controller ]
23
+ @resource_klass ||= self . class . resource_for ( params [ :controller ] . split ( '/' ) . last ) if params [ :controller ]
24
24
25
25
unless params . nil?
26
26
case params [ :action ]
@@ -76,10 +76,14 @@ def parse_fields(params)
76
76
fields . each do |type , values |
77
77
underscored_type = unformat_key ( type )
78
78
fields [ type ] = [ ]
79
- type_resource = self . class . resource_for ( underscored_type )
80
- if type_resource . nil? || ! ( @resource_klass . _type == underscored_type ||
81
- @resource_klass . _has_association? ( underscored_type ) )
79
+ begin
80
+ type_resource = self . class . resource_for ( underscored_type )
81
+ rescue NameError
82
82
@errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type ) . errors )
83
+ end
84
+ if type_resource . nil? || !( @resource_klass . _type == underscored_type ||
85
+ @resource_klass . _has_association? ( underscored_type ) )
86
+ @errors . concat ( JSONAPI ::Exceptions ::InvalidResource . new ( type ) . errors )
83
87
else
84
88
unless values . nil?
85
89
valid_fields = type_resource . fields . collect { |key | format_key ( key ) }
Original file line number Diff line number Diff line change @@ -11,15 +11,19 @@ def resource_for(type)
11
11
resource_name = JSONAPI ::Resource . _resource_name_from_type ( type )
12
12
Object . const_get resource_name if resource_name
13
13
rescue NameError
14
- nil
14
+ raise NameError , "JSONAPI: Could not find resource ' #{ type } '. (Class #{ resource_name } not found)"
15
15
end
16
16
else
17
17
def resource_for ( type )
18
18
resource_name = JSONAPI ::Resource . _resource_name_from_type ( type )
19
- resource_name . safe_constantize if resource_name
19
+ resource = resource_name . safe_constantize if resource_name
20
+ if resource . nil?
21
+ raise NameError , "JSONAPI: Could not find resource '#{ type } '. (Class #{ resource_name } not found)"
22
+ end
23
+ resource
20
24
end
21
25
end
22
26
# :nocov:
23
27
end
24
28
end
25
- end
29
+ end
Original file line number Diff line number Diff line change @@ -528,7 +528,7 @@ class PreferencesResource < JSONAPI::Resource
528
528
has_one :author , foreign_key : :person_id
529
529
has_many :friends
530
530
531
- def self . find_by_key ( key , context : nil )
531
+ def self . find_by_key ( key , options = { } )
532
532
new ( Preferences . first )
533
533
end
534
534
end
You can’t perform that action at this time.
0 commit comments