12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/generators/jsonapi/resource_generator.rb', line 12
def copy_resource_file
unless @options['no-controller']
to = File.join('app/controllers', class_path, "#{file_name.pluralize}_controller.rb")
template('controller.rb.erb', to)
end
unless @options['no-serializer']
to = File.join('app/serializers', class_path, "serializable_#{file_name}.rb")
template('serializer.rb.erb', to)
end
unless 'ApplicationResource'.safe_constantize
to = File.join('app/resources', class_path, "application_resource.rb")
template('application_resource.rb.erb', to)
end
unless @options['no-payload']
to = File.join('spec/payloads', class_path, "#{file_name}.rb")
template('payload.rb.erb', to)
end
unless @options['no-strong-resources']
inject_into_file 'config/initializers/strong_resources.rb', after: "StrongResources.configure do\n" do <<-STR
strong_resource :#{file_name} do
# Your attributes go here, e.g.
# attribute :name, :string
end
STR
end
end
unless @options['no-route']
inject_into_file 'config/routes.rb', after: "scope '/api' do\n scope '/v1' do\n" do <<-STR
resources :#{type}
STR
end
end
unless @options['no-test']
to = File.join "spec/api/v1/#{file_name.pluralize}",
class_path,
"index_spec.rb"
template('index_request_spec.rb.erb', to)
to = File.join "spec/api/v1/#{file_name.pluralize}",
class_path,
"show_spec.rb"
template('show_request_spec.rb.erb', to)
to = File.join "spec/api/v1/#{file_name.pluralize}",
class_path,
"create_spec.rb"
template('create_request_spec.rb.erb', to)
to = File.join "spec/api/v1/#{file_name.pluralize}",
class_path,
"update_spec.rb"
template('update_request_spec.rb.erb', to)
to = File.join "spec/api/v1/#{file_name.pluralize}",
class_path,
"destroy_spec.rb"
template('destroy_request_spec.rb.erb', to)
end
to = File.join('app/resources', class_path, "#{file_name}_resource.rb")
template('resource.rb.erb', to)
end
|