Class: Shanty::ProjectTemplate

Inherits:
Object
  • Object
show all
Extended by:
Mixins::AttrCombinedAccessor
Defined in:
lib/shanty/project_template.rb

Overview

Public: Allows creation of a project using a discoverer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AttrCombinedAccessor

attr_combined_accessor

Constructor Details

#initialize(root, path) ⇒ ProjectTemplate

Returns a new instance of ProjectTemplate.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/shanty/project_template.rb', line 13

def initialize(root, path)
  fail 'Path to project must be a directory.' unless File.directory?(path)

  @root = root
  @path = path
  @name = File.basename(path)
  @type = StaticProject
  @priority = 0
  @plugins = []
  @parents = []
  @options = []

  execute_shantyfile
end

Instance Attribute Details

#name=(value) ⇒ Object (writeonly)

Sets the attribute name

Parameters:

  • value

    the value to set the attribute name to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def name=(value)
  @name = value
end

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def options=(value)
  @options = value
end

#parents=(value) ⇒ Object (writeonly)

Sets the attribute parents

Parameters:

  • value

    the value to set the attribute parents to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def parents=(value)
  @parents = value
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/shanty/project_template.rb', line 11

def path
  @path
end

#plugins=(value) ⇒ Object (writeonly)

Sets the attribute plugins

Parameters:

  • value

    the value to set the attribute plugins to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def plugins=(value)
  @plugins = value
end

#priority=(value) ⇒ Object (writeonly)

Sets the attribute priority

Parameters:

  • value

    the value to set the attribute priority to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def priority=(value)
  @priority = value
end

#rootObject (readonly)

Returns the value of attribute root.



11
12
13
# File 'lib/shanty/project_template.rb', line 11

def root
  @root
end

#type=(value) ⇒ Object (writeonly)

Sets the attribute type

Parameters:

  • value

    the value to set the attribute type to.



10
11
12
# File 'lib/shanty/project_template.rb', line 10

def type=(value)
  @type = value
end

Instance Method Details

#after_create(&block) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/shanty/project_template.rb', line 49

def after_create(&block)
  if block.nil?
    @after_create
  else
    @after_create = block
  end
end

#execute_shantyfileObject



28
29
30
31
32
33
34
# File 'lib/shanty/project_template.rb', line 28

def execute_shantyfile
  shantyfile_path = File.join(@path, 'Shantyfile')

  return unless File.exist?(shantyfile_path)

  instance_eval(File.read(shantyfile_path), shantyfile_path)
end

#option(key, value) ⇒ Object



45
46
47
# File 'lib/shanty/project_template.rb', line 45

def option(key, value)
  @options[key] = value
end

#parent(parent) ⇒ Object



40
41
42
43
# File 'lib/shanty/project_template.rb', line 40

def parent(parent)
  # Will make the parent path relative to the root if (and only if) it is relative.
  @parents << File.expand_path(parent, @root)
end

#plugin(plugin) ⇒ Object



36
37
38
# File 'lib/shanty/project_template.rb', line 36

def plugin(plugin)
  @plugins << plugin
end