class NestedGeneratorsBaseGenerator
Constants
- RETURN
- SCOPES
Private Instance Methods
base?()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 29 def base? File.exist?(base_file_path) end
base_file_path()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 33 def base_file_path @base_file_path ||= "app/#{@type.pluralize}/application_#{@type}.rb" end
class_file_name()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 45 def class_file_name @class_file_name ||= "#{last_part.underscore}_#{@type}" end
class_file_path()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 37 def class_file_path "#{(%w[app] + modules.map(&:underscore)).join('/')}/#{class_file_name}.rb" end
class_indent()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 73 def class_indent @class_indent ||= indent * modules.length end
class_spec_file_path()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 41 def class_spec_file_path "#{(%w[spec] + modules.map(&:underscore)).join('/')}/#{class_file_name}_spec.rb" end
close_modules_nesting()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 61 def close_modules_nesting modules.each.with_index.map { |_namespace, index| "#{indent * index}end" }.reverse.join(RETURN) end
code_indent()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 77 def code_indent @code_indent ||= indent * (modules.length + 1) end
create_base()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 15 def create_base return if base? template 'base_class_template.erb', base_file_path end
create_class_file()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 21 def create_class_file template 'class_template.erb', class_file_path end
create_class_spec_file()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 25 def create_class_spec_file template 'class_spec_template.erb', class_spec_file_path end
end_class()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 69 def end_class "#{class_indent}end#{RETURN}" end
in_scope?(method, name)
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 85 def in_scope?(method, name) " #{method.split(':')&.[](0)} " == " #{name} " end
indent()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 81 def indent @indent ||= ' ' end
last_part()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 49 def last_part @last_part ||= class_name.split('::')[-1] end
modules()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 53 def modules @modules ||= [@type.pluralize.capitalize] + class_name.split('::')[0..-2] end
open_class()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 65 def open_class "#{RETURN}#{class_indent}class #{last_part}#{@type.capitalize}" + (base? ? " < Application#{@type.capitalize}" : '') end
open_modules_nesting()
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 57 def open_modules_nesting modules.each.with_index.map { |namespace, index| "#{indent * index}module #{namespace}" }.join(RETURN) end
rspec_empty_message(method = nil)
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 101 def rspec_empty_message(method = nil) "pending 'add some examples to (or delete) #{class_spec_file_path}#{method.nil? ? '' : ('#' + method)}'" end
scope?(name)
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 89 def scope?(name) methods&.any? { |method| in_scope?(method, name) } end
scope_methods(name)
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 93 def scope_methods(name) methods&.select { |method| in_scope?(method, name) }&.map(&:strip) end
strip_scope(method, name)
click to toggle source
# File lib/generators/nested_generators_base_generator.rb, line 97 def strip_scope(method, name) method.gsub("#{name}:", '') end