lib/generators/sparrow/entity/entity_generator.rb in sparrow-entity-0.1.2 vs lib/generators/sparrow/entity/entity_generator.rb in sparrow-entity-0.1.3
- old
+ new
@@ -9,11 +9,11 @@
class EntityGenerator < Rails::Generators::NamedBase
# 默认的引入应用的相对安装路径
TARGET_RELATIVE_PATH = 'app/entities'
# 单模组模板
- MODULE_TEMPLATE =<<~MODULE.strip
+ MODULE_TEMPLATE = <<~MODULE.strip
module %{module_name}
%{module_content}
end
MODULE
@@ -57,15 +57,15 @@
def indent_level
@indent_level = @indent_level.blank? ? 0 : @indent_level + 1
end
def __module_content__(name, content)
- return MODULE_TEMPLATE % { module_name: name.camelize, module_content: indent(content, 2) }
+ MODULE_TEMPLATE % { module_name: name.camelize, module_content: indent(content, 2) }
end
def __class_content__
- return CLASS_TEMPLATE % { class_name: file_name.camelize }
+ CLASS_TEMPLATE % { class_name: file_name.camelize }
end
def __class_body__
results = __class_content__
class_path.reverse.each { |sub| results = __module_content__(sub, results) } if class_path.present?
@@ -74,9 +74,11 @@
def __module_body__(paths = [])
current = paths.shift
content = paths.size.positive? ? __module_body__(paths) : ''
result = current ? __module_content__(current, content) : ''
- result.each_line.select { |line| line.present? }.join
+ result = result.each_line.select(&:present?).join
+ result << "\n"
+ result
end
end
end