class BaseGenerator

Base class for all generators to come. If you want to override some behaviour, all you got to do is override a method in the child class.

Public Instance Methods

copy_pattern_file() click to toggle source

Creates the file for the requested pattern based on a template file.

# File lib/generators/base_generator.rb, line 11
def copy_pattern_file
  template "#{pattern_name}.rb", generated_file_path
end
copy_pattern_test_file() click to toggle source

Creates the test file for the request pattern based on a template file.

# File lib/generators/base_generator.rb, line 16
def copy_pattern_test_file
  template "#{pattern_name}_#{test_suite_identifier}.rb", generated_test_file_path
end

Private Instance Methods

class_name() click to toggle source

Determines the class name based on the file name given by the user.

# File lib/generators/base_generator.rb, line 23
def class_name
  file_name.classify + suffix.classify
end
folder_name() click to toggle source
# File lib/generators/base_generator.rb, line 32
def folder_name
  pattern_name.pluralize
end
generated_file_path() click to toggle source

Generates the file path. Ex: app/services/authentication.rb

# File lib/generators/base_generator.rb, line 44
def generated_file_path
  "app/#{folder_name}/#{file_name}#{suffix}.rb"
end
generated_test_file_path() click to toggle source

Generates the test file path. Ex: spec/services/authentication_spec.rb

# File lib/generators/base_generator.rb, line 56
def generated_test_file_path
  "#{test_suite_identifier}/#{folder_name}/#{file_name}#{suffix}_#{test_suite_identifier}.rb"
end
pattern_name() click to toggle source

This method must be overrided in the child classes.

# File lib/generators/base_generator.rb, line 28
def pattern_name
  raise NotImplementedError
end
suffix() click to toggle source

Generates the pattern suffix. Ex: _service

# File lib/generators/base_generator.rb, line 38
def suffix
  options.no_suffix? ? "" : "_#{pattern_name}"
end
test_suite_identifier() click to toggle source
# File lib/generators/base_generator.rb, line 48
def test_suite_identifier
  identifier = "spec"
  identifier = "test" if options.minitest?
  identifier
end