Class: Dry::Generators::MonadGenerator
- Inherits:
-
Base
- Object
- Rails::Generators::NamedBase
- Base
- Dry::Generators::MonadGenerator
show all
- Defined in:
- lib/generators/dry/monad/monad_generator.rb
Constant Summary
Constants inherited
from Base
Base::DRY_PATH, Base::MONADS_PATH, Base::SPEC_PATH, Base::STRUCTS_PATH, Base::TEST_PATH, Base::VALIDATIONS_PATH
Instance Method Summary
collapse
Instance Method Details
#check_requirements ⇒ Object
8
9
10
|
# File 'lib/generators/dry/monad/monad_generator.rb', line 8
def check_requirements
raise 'NAME must be provided' unless file_name.present?
end
|
#copy_monad ⇒ Object
17
18
19
20
|
# File 'lib/generators/dry/monad/monad_generator.rb', line 17
def copy_monad
path = File.join(MONADS_PATH, "#{@name}.rb")
template 'monad_template.rb', path
end
|
#copy_spec ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/generators/dry/monad/monad_generator.rb', line 22
def copy_spec
if Dir.exist? File.join(Rails.root, 'spec')
spec_path = File.join(SPEC_PATH, 'monads')
path = File.join(spec_path, "#{@name}_spec.rb")
template 'monad_spec_template.rb', path
end
end
|
#copy_test ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/generators/dry/monad/monad_generator.rb', line 30
def copy_test
if Dir.exist? File.join(Rails.root, 'test')
test_path = File.join(TEST_PATH, 'monads')
path = File.join(test_path, "#{@name}_test.rb")
template 'monad_test_template.rb', path
end
end
|
#set_instance_variables ⇒ Object
12
13
14
15
|
# File 'lib/generators/dry/monad/monad_generator.rb', line 12
def set_instance_variables
@name = file_name.underscore
@class_name = "#{@name.camelize}"
end
|