Created
August 9, 2018 11:34
-
-
Save 8parth/37336816b887072d9459b84e8e4401c8 to your computer and use it in GitHub Desktop.
Service Class Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# lib/generators/service/service_generator.rb | |
require 'rails/generators' | |
class ServiceGenerator < Rails::Generators::NamedBase | |
def create_service_file | |
directories = name.split('/') | |
directories.pop | |
directory_name = directories.join('/') | |
create_file "app/services/#{directory_name}/#{file_name}.rb", <<-FILE | |
class #{class_name} | |
def initialize | |
end | |
def call | |
end | |
end | |
FILE | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/generators/service/USAGE | |
Description: | |
Generates Service Class | |
Example: | |
rails generate service Thing | |
This will create: | |
app/services/thing.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment