Class: Prigner::Builder

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/prigner/builder.rb

Overview

The project builder

The Builder class is a main handler of the projects and templates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, template) ⇒ Builder

Build a new project based on a template.



15
16
17
# File 'lib/prigner/builder.rb', line 15

def initialize(project, template)
  @project, @template = project, template
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'lib/prigner/builder.rb', line 10

def project
  @project
end

#templateObject (readonly)

Returns the value of attribute template.



12
13
14
# File 'lib/prigner/builder.rb', line 12

def template
  @template
end

Instance Method Details

#make_project_directoriesObject

:yields: path, info



24
25
26
27
28
29
30
31
32
# File 'lib/prigner/builder.rb', line 24

def make_project_directories #:yields: path, info
  @template.directories.inject({}) do |hash, basedir|
    directory = basedir.gsub(/\((.*?)\)/){ @project.send($1) }
    path      = File.join(@project.path, directory)
    mkdir_p(path)
    hash[no_pwd(path)] = File.stat(path)
    hash
  end
end

#make_project_files(option = :required) ⇒ Object

:yields: path, info



34
35
36
37
38
39
40
41
42
43
# File 'lib/prigner/builder.rb', line 34

def make_project_files(option = :required) #:yields: path, info
  @template.models[option.to_sym].inject({}) do |hash, (model, basename)|
    file = basename.gsub(/\((.*?)\)/){ project.send($1) }
    path = File.join(@project.path, file)
    model.binder = Prigner::Binder.new(@project, @template.options)
    model.write(path)
    hash[no_pwd(model.file_written)] = File.stat(model.file_written)
    hash
  end if @template.models.has_key?(option.to_sym)
end

#make_project_files_for_option(option) ⇒ Object



45
46
47
48
# File 'lib/prigner/builder.rb', line 45

def make_project_files_for_option(option)
  @template.initialize_models_for_option(option)
  self.make_project_files(option)
end

#make_project_pathObject

:yields: path, info



19
20
21
22
# File 'lib/prigner/builder.rb', line 19

def make_project_path #:yields: path, info
  mkdir_p(@project.path)
  { no_pwd(@project.path) => File.stat(@project.path) }
end