Class: Nutella::TemplateCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/commands/meta/template_command.rb

Overview

This class describes a template command which can be either install or template It is mostly a commodity class for code reuse.

Direct Known Subclasses

Install, Template

Instance Method Summary collapse

Instance Method Details

#run(args = nil) ⇒ Object



10
11
12
# File 'lib/commands/meta/template_command.rb', line 10

def run (args=nil)
  console.error 'Running generic TemplateCommand!!! WAT?'
end

#validate_nutella_file_json(json) ⇒ Object



39
40
41
# File 'lib/commands/meta/template_command.rb', line 39

def validate_nutella_file_json( json )
  !json['name'].nil? && !json['version'].nil? && !json['type'].nil? && (json['type']=='bot' || json['type']=='interface')
end

#validate_template(dir) ⇒ Object

Validates a template in a certain folder

Parameters:

  • dir (String)

    the directory where the template is stored



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/commands/meta/template_command.rb', line 17

def validate_template( dir )
  # Parse and validate the template's nutella.json file
  begin
    template_nutella_file_json = JSON.parse(IO.read("#{dir}/nutella.json"))
  rescue
    return false
  end
  return false unless validate_nutella_file_json template_nutella_file_json
  # If template is a bot, perform the appropriate checks
  if template_nutella_file_json['type']=='bot'
    # Is there a mandatory 'startup' script and is it executable
    return false unless File.executable? "#{dir}/startup"
  end
  # If template is an interface, perform the appropriate checks
  if template_nutella_file_json['type']=='interface'
    # Is there the mandatory index.html file
    return false unless File.exist? "#{dir}/index.html"
  end
  true
end