Class: SerializableGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/serializable/serializable_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_serializer_fileObject



14
15
16
17
18
# File 'lib/generators/serializable/serializable_generator.rb', line 14

def create_serializer_file
  @serializer_name = options[:name] || "#{class_name}Serializer"
  file_name = @serializer_name.underscore
  template "serializer.erb", File.join("app/serializers", class_path, "#{file_name}.rb")
end

#create_test_fileObject



20
21
22
23
# File 'lib/generators/serializable/serializable_generator.rb', line 20

def create_test_file
  @serializer_name = options[:name] || "#{class_name}Serializer"
  (Bundler.load.specs.find { |s| s.name == "rspec-rails" }) ? create_rspec_test_file : create_minitest_test_file
end

#modify_model_fileObject



8
9
10
11
12
# File 'lib/generators/serializable/serializable_generator.rb', line 8

def modify_model_file
  inject_into_class File.join("app/models", class_path, "#{class_name.underscore}.rb"), class_name do
    "  include Barley::Serializable\n"
  end
end