lib/hanami/commands/generate/model.rb in hanami-0.7.3 vs lib/hanami/commands/generate/model.rb in hanami-0.8.0
- old
+ new
@@ -39,12 +39,12 @@
# Validates that a model name was provided
#
# @since 0.6.0
# @api private
def model_name_not_blank
- if model_name.nil? || model_name.strip.empty?
- raise ArgumentError.new('Model name nil or empty.')
+ if argument_blank?(model_name)
+ raise ArgumentError.new('Model name is missing')
end
end
# Validates that the provided model name doesn't start with numbers
#
@@ -55,11 +55,11 @@
raise ArgumentError.new("Invalid model name. The model name shouldn't begin with a number.")
end
end
def model_root
- Pathname.new('lib').join(::File.basename(Dir.getwd))
+ Pathname.new('lib').join(project_name)
end
# @since 0.5.0
# @api private
def entity_path
@@ -73,23 +73,29 @@
end
# @since 0.5.0
# @api private
def entity_spec_path
- target_path.join('spec', ::File.basename(Dir.getwd), 'entities', "#{ model_name_underscored }_spec.rb")
+ target_path.join('spec', project_name, 'entities', "#{ model_name_underscored }_spec.rb")
end
# @since 0.5.0
# @api private
def repository_spec_path
- target_path.join('spec', ::File.basename(Dir.getwd), 'repositories',
+ target_path.join('spec', project_name, 'repositories',
"#{ model_name_underscored }_repository_spec.rb")
end
# @since 0.5.0
# @api private
def model_name_underscored
Utils::String.new(model_name).underscore
+ end
+
+ # @since 0.8.0
+ # @api private
+ def project_name
+ Utils::String.new(Hanami::Environment.new.project_name).underscore
end
end
end
end
end