Class: Mygen::Generator

Inherits:
Object
  • Object
show all
Includes:
Files, Naming, Templates
Defined in:
lib/mygen/generator.rb

Direct Known Subclasses

Plugins::MygenGenerator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Templates

#make_template_tree, #make_template_tree_in_current_dir, #parse, #parse_templates

Methods included from Files

#directory_exists?, #file_destination, #internal_template_files, #internal_template_source_dir, #move_file_in_place, #template_dirs, #template_files

Methods included from Naming

#camel_case, #cc_name, #d_name, #dash_case, #method_name, #no_case, #s_name, #snake_case

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



14
15
16
# File 'lib/mygen/generator.rb', line 14

def initialize
  @template_source_dir = File.join(ENV['HOME'], ".mygen", "plugins", generator_name, "templates").tr('\\', '/')
end

Instance Attribute Details

#dest_dirObject

Returns the value of attribute dest_dir.



12
13
14
# File 'lib/mygen/generator.rb', line 12

def dest_dir
  @dest_dir
end

#dry_runObject

Returns the value of attribute dry_run.



12
13
14
# File 'lib/mygen/generator.rb', line 12

def dry_run
  @dry_run
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/mygen/generator.rb', line 12

def name
  @name
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/mygen/generator.rb', line 12

def options
  @options
end

#template_source_dirObject

Returns the value of attribute template_source_dir.



12
13
14
# File 'lib/mygen/generator.rb', line 12

def template_source_dir
  @template_source_dir
end

Class Method Details

.descendantsObject



18
19
20
# File 'lib/mygen/generator.rb', line 18

def self.descendants
  ObjectSpace.each_object(Class).select { |klass| klass < self }
end

Instance Method Details

#descriptionObject



22
23
24
# File 'lib/mygen/generator.rb', line 22

def description
  "Plugin has no description"
end

#fileutilsObject



30
31
32
# File 'lib/mygen/generator.rb', line 30

def fileutils
  dry_run ? FileUtils::DryRun : FileUtils::Verbose
end

#generator_nameObject



26
27
28
# File 'lib/mygen/generator.rb', line 26

def generator_name
  snake_case(self.class.name)
end

#parent_dirs_dont_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/mygen/generator.rb', line 34

def parent_dirs_dont_exist?(path)
  parent_dir = File.expand_path("..", path)
  return false if path.include?('__')
  return !File.exist?(path)
end