Class: Skeletor::Skeletons::Skeleton

Inherits:
Object
  • Object
show all
Defined in:
lib/skeletor/skeletons/skeleton.rb

Overview

The Skeleton class provides a wrapper round the template file and handles loading it and validating it, as well as providing default values for any missing sections.

Constant Summary collapse

SCHEMA_FILE =

Defines the location to the required schema file for the templates

File.join Skeletons::Loader::TEMPLATE_PATH,'template-schema.yml'

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ Skeleton

Creates a new Skeleton instance from template



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/skeletor/skeletons/skeleton.rb', line 16

def initialize(template)
  
  begin
    @template = Loader.load_template(template)
    validator = Grayskull::Validator.new(@template,SCHEMA_FILE)
    results = validator.validate
    if results["result"]
      puts "Validated Successfully!"
      @directory_structure = @template["directory_structure"] || []
      @tasks = @template["tasks"] || {}
      @includes = @template["includes"] || {}
      @path = @template["path"]
    else
      puts 'Validation Failed with ' + @errors.count.to_s + ' errors';
      puts ''
      results["errors"].each{
        |error|
        puts error            
      }
      exit
    end
  rescue LoadError => e
    puts e.message
    exit
  end
    
end

Instance Method Details

#directory_structureObject

Returns the directory structure section



45
46
47
# File 'lib/skeletor/skeletons/skeleton.rb', line 45

def directory_structure
  @directory_structure
end

#includesObject

Returns the includes section



55
56
57
# File 'lib/skeletor/skeletons/skeleton.rb', line 55

def includes
  @includes
end

#pathObject

Returns the template path



60
61
62
# File 'lib/skeletor/skeletons/skeleton.rb', line 60

def path
  @path
end

#tasksObject

Returns the tasks section



50
51
52
# File 'lib/skeletor/skeletons/skeleton.rb', line 50

def tasks
  @tasks
end