Class: Embork::Generator

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

Defined Under Namespace

Classes: ErbHelpers

Constant Summary collapse

BLUEPRINT_DIR =
File.expand_path('../../../blueprint', __FILE__).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_name, options) ⇒ Generator

Returns a new instance of Generator.



14
15
16
17
18
19
20
# File 'lib/embork/generator.rb', line 14

def initialize(package_name, options)
  @package_name = package_name
  @logger = Embork::Logger.new STDOUT, :simple
  read_erb_files
  read_dot_files
  set_project_path(options[:directory])
end

Instance Attribute Details

#dot_filesObject (readonly)

Returns the value of attribute dot_files.



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

def dot_files
  @dot_files
end

#erb_filesObject (readonly)

Returns the value of attribute erb_files.



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

def erb_files
  @erb_files
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



10
11
12
# File 'lib/embork/generator.rb', line 10

def project_path
  @project_path
end

Instance Method Details

#generateObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/embork/generator.rb', line 45

def generate
  check_for_npm
  print_banner
  copy_files
  process_erb
  move_dot_files
  install_npm_deps
  install_bower_deps
  bundle
  init_git
  print_success
end

#read_dot_filesObject



27
28
29
30
# File 'lib/embork/generator.rb', line 27

def read_dot_files
  list_file_path = File.join(BLUEPRINT_DIR, 'dotfiles')
  @dot_files = File.readlines(list_file_path).map{ |f| f.strip }
end

#read_erb_filesObject



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

def read_erb_files
  list_file_path = File.join(BLUEPRINT_DIR, 'erbfiles')
  @erb_files = File.readlines(list_file_path).map{ |f| f.strip }
end

#set_project_path(directory) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/embork/generator.rb', line 32

def set_project_path(directory)
  if directory.nil?
    @project_path = File.join Dir.pwd, @package_name
  else
    p = Pathname.new directory
    if p.absolute?
      @project_path = p.to_s
    else
      @project_path = File.expand_path p.to_s, Dir.pwd
    end
  end
end