Class: Greg::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/greg/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, template_name:, output_directory: ".", force: false) ⇒ Generator

Returns a new instance of Generator.



11
12
13
14
15
16
17
18
# File 'lib/greg/generator.rb', line 11

def initialize(name:, template_name: , output_directory: ".", force: false)
  @name = name
  @template_name = template_name
  @output_directory = Pathname(output_directory + "/" + name).expand_path
  @current_dir = Pathname(".").expand_path

  @force = force
end

Instance Attribute Details

#current_dirObject (readonly)

Returns the value of attribute current_dir.



7
8
9
# File 'lib/greg/generator.rb', line 7

def current_dir
  @current_dir
end

#forceObject (readonly)

Returns the value of attribute force.



8
9
10
# File 'lib/greg/generator.rb', line 8

def force
  @force
end

#generatorObject (readonly)

Returns the value of attribute generator.



9
10
11
# File 'lib/greg/generator.rb', line 9

def generator
  @generator
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/greg/generator.rb', line 3

def name
  @name
end

#output_directoryObject (readonly)

Returns the value of attribute output_directory.



6
7
8
# File 'lib/greg/generator.rb', line 6

def output_directory
  @output_directory
end

#template_nameObject (readonly)

Returns the value of attribute template_name.



4
5
6
# File 'lib/greg/generator.rb', line 4

def template_name
  @template_name
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



5
6
7
# File 'lib/greg/generator.rb', line 5

def template_path
  @template_path
end

Instance Method Details

#filesObject



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

def files
  []
end

#inside_dir(&block) ⇒ Object



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

def inside_dir(&block)
  Dir.chdir(output_directory, &block)
end

#runObject



20
21
22
23
24
# File 'lib/greg/generator.rb', line 20

def run
  create_directory
  create_files
  self
end

#template_dirObject



34
35
36
# File 'lib/greg/generator.rb', line 34

def template_dir
  Pathname(Greg.templates_dir + "/" +  template_name).expand_path.to_s
end