Class: Dry::Generators::StructGenerator
- Inherits:
-
Base
- Object
- Rails::Generators::NamedBase
- Base
- Dry::Generators::StructGenerator
show all
- Defined in:
- lib/generators/dry/struct/struct_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/struct/struct_generator.rb', line 8
def check_requirements
raise 'NAME must be provided' unless file_name.present?
end
|
#copy_spec ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/generators/dry/struct/struct_generator.rb', line 22
def copy_spec
if Dir.exist? File.join(Rails.root, 'spec')
spec_path = File.join(SPEC_PATH, 'structs')
path = File.join(spec_path, "#{@name}_spec.rb")
template 'struct_spec_template.rb', path
end
end
|
#copy_struct ⇒ Object
17
18
19
20
|
# File 'lib/generators/dry/struct/struct_generator.rb', line 17
def copy_struct
path = File.join(STRUCTS_PATH, "#{@name}.rb")
template 'struct_template.rb', path
end
|
#copy_test ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/generators/dry/struct/struct_generator.rb', line 30
def copy_test
if Dir.exist? File.join(Rails.root, 'test')
test_path = File.join(TEST_PATH, 'structs')
path = File.join(test_path, "#{@name}_test.rb")
template 'struct_test_template.rb', path
end
end
|
#set_instance_variables ⇒ Object
12
13
14
15
|
# File 'lib/generators/dry/struct/struct_generator.rb', line 12
def set_instance_variables
@name = file_name.underscore
@class_name = "#{@name.camelize}"
end
|