mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Generate a serializer with each new model
This commit is contained in:
parent
d5d917ea56
commit
a2d73faa63
@ -3,6 +3,17 @@ require "active_support/core_ext/string/inflections"
|
||||
require "active_model"
|
||||
require "active_model/serializer"
|
||||
|
||||
if defined?(Rails)
|
||||
module ActiveModel
|
||||
class Railtie < Rails::Railtie
|
||||
generators do |app|
|
||||
Rails::Generators.configure!(app.config.generators)
|
||||
require "generators/resource_override"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ActiveModel::SerializerSupport
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
|
||||
13
lib/generators/resource_override.rb
Normal file
13
lib/generators/resource_override.rb
Normal file
@ -0,0 +1,13 @@
|
||||
require "rails/generators"
|
||||
require "rails/generators/rails/resource/resource_generator"
|
||||
|
||||
module Rails
|
||||
module Generators
|
||||
ResourceGenerator.class_eval do
|
||||
def add_serializer
|
||||
invoke "serializer"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,7 +30,7 @@ module Rails
|
||||
# Only works on 3.2
|
||||
# elsif (n = Rails::Generators.namespace) && n.const_defined?(:ApplicationSerializer)
|
||||
# "ApplicationSerializer"
|
||||
elsif Object.const_defined?(:ApplicationSerializer)
|
||||
elsif defined?(:ApplicationSerializer)
|
||||
"ApplicationSerializer"
|
||||
else
|
||||
"ActiveModel::Serializer"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user