Class: Generamba::RambaspecValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/generamba/template/helpers/rambaspec_validator.rb

Overview

Provides methods that validate .rambaspec file existance and structure

Class Method Summary collapse

Class Method Details

.validate_spec(template_name, template_path) ⇒ Bool

Validates the structure of a .rambaspec file for a given template

Parameters:

  • template_name (String)

    The name of the template

  • template_path (String)

    The local filepath to the template

Returns:

  • (Bool)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generamba/template/helpers/rambaspec_validator.rb', line 23

def self.validate_spec(template_name, template_path)
  spec_path = self.obtain_spec_path(template_name, template_path)

  spec_source = IO.read(spec_path)
  spec_template = Liquid::Template.parse(spec_source)
  spec_content = spec_template.render
  spec = YAML.load(spec_content)

  is_spec_valid =
      spec[TEMPLATE_NAME_KEY] != nil &&
      spec[TEMPLATE_AUTHOR_KEY] != nil &&
      spec[TEMPLATE_VERSION_KEY] != nil &&
      (spec[TEMPLATE_CODE_FILES_KEY] != nil || spec[TEMPLATE_TEST_FILES_KEY] != nil)
  return is_spec_valid
end

.validate_spec_existance(template_name, template_path) ⇒ Bool

Validates the existance of a .rambaspec file for a given template

Parameters:

  • template_name (String)

    The name of the template

  • template_path (String)

    The local filepath to the template

Returns:

  • (Bool)


12
13
14
15
# File 'lib/generamba/template/helpers/rambaspec_validator.rb', line 12

def self.validate_spec_existance(template_name, template_path)
  local_spec_path = self.obtain_spec_path(template_name, template_path)
  File.file?(local_spec_path)
end