skeletor 0.7.0 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/skeletor/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'grayskull'
2
3
 
3
4
  module Skeletor
4
5
 
@@ -44,8 +45,19 @@ module Skeletor
44
45
  # Loads a template, creates a new *Validator* and validates the template
45
46
  def validate(template)
46
47
  skeleton = Skeletons::Loader.loadTemplate(template)
47
- validator = Skeletons::Validator.new(skeleton)
48
- validator.validate()
48
+ validator = Grayskull::Validator.new(skeleton,Skeletons::Skeleton::SCHEMA_FILE)
49
+ results = validator.validate
50
+
51
+ if !results['result']
52
+ puts 'Validation Failed with ' + @errors.count.to_s + ' errors';
53
+ puts ''
54
+ results["errors"].each{
55
+ |error|
56
+ puts error
57
+ }
58
+ else
59
+ puts 'Validated Successfully!'
60
+ end
49
61
  end
50
62
 
51
63
  end
@@ -1,3 +1,5 @@
1
+ require 'grayskull'
2
+
1
3
  module Skeletor
2
4
 
3
5
  module Skeletons
@@ -7,18 +9,29 @@ module Skeletor
7
9
  # default values for any missing sections.
8
10
  class Skeleton
9
11
 
12
+ # Defines the location to the required schema file for the templates
13
+ SCHEMA_FILE = File.join Skeletons::Loader::TEMPLATE_PATH,'template-schema.yml'
14
+
10
15
  #Creates a new *Skeleton* instance from `template`
11
16
  def initialize(template)
12
17
 
13
18
  begin
14
19
  @template = Loader.loadTemplate(template)
15
- validator = Validator.new(@template)
16
- if validator.validate
20
+ validator = Grayskull::Validator.new(@template,SCHEMA_FILE)
21
+ results = validator.validate
22
+ if results["result"]
23
+ puts "Validated Successfully!"
17
24
  @directory_structure = @template["directory_structure"] || []
18
25
  @tasks = @template["tasks"] || {}
19
26
  @includes = @template["includes"] || {}
20
27
  @path = @template["path"]
21
28
  else
29
+ puts 'Validation Failed with ' + @errors.count.to_s + ' errors';
30
+ puts ''
31
+ results["errors"].each{
32
+ |error|
33
+ puts error
34
+ }
22
35
  exit
23
36
  end
24
37
  rescue LoadError => e
@@ -3,7 +3,6 @@ module Skeletor
3
3
  # Contains the classes for dealing with the project templates
4
4
  module Skeletons
5
5
  autoload :Loader, 'skeletor/skeletons/loader'
6
- autoload :Validator, 'skeletor/skeletons/validator'
7
6
  autoload :Skeleton, 'skeletor/skeletons/skeleton'
8
7
  end
9
8
 
@@ -1,6 +1,6 @@
1
1
  sections:
2
2
  - name: directory_structure
3
- required: yes
3
+ required: no
4
4
  type: Array
5
5
  ok_empty: yes
6
6
  accepts:
@@ -1,4 +1,4 @@
1
1
  module Skeletor
2
2
  # Current version number
3
- VERSION="0.7.0"
3
+ VERSION="0.8.4"
4
4
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 7
8
- - 0
9
- version: 0.7.0
7
+ - 8
8
+ - 4
9
+ version: 0.8.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Will McKenzie
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-29 00:00:00 +01:00
17
+ date: 2011-10-02 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -23,13 +23,30 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- version: "0"
30
+ - 14
31
+ - 6
32
+ version: 0.14.6
31
33
  type: :runtime
32
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: grayskull
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 1
46
+ - 6
47
+ version: 0.1.6
48
+ type: :runtime
49
+ version_requirements: *id002
33
50
  description: Skeletor is a command line gem for creating project skeletons based on a YAML template. It will create files and folders, including pulling in specified includes, and run tasks to set up your project.
34
51
  email:
35
52
  - will@oinutter.co.uk
@@ -48,7 +65,6 @@ files:
48
65
  - lib/skeletor/protocols/https.rb
49
66
  - lib/skeletor/skeletons/loader.rb
50
67
  - lib/skeletor/skeletons/skeleton.rb
51
- - lib/skeletor/skeletons/validator.rb
52
68
  - lib/skeletor/skeletons.rb
53
69
  - lib/skeletor/tasks.rb
54
70
  - lib/skeletor/version.rb
@@ -1,186 +0,0 @@
1
- require 'yaml'
2
-
3
- module Skeletor
4
-
5
- module Skeletons
6
-
7
- # *Validator* handles validation of the loaded project template files against
8
- # the required schema
9
-
10
- class Validator
11
-
12
- # Defines the location to the required schema file for the templates
13
- SCHEMA_FILE = File.join Skeletons::Loader::TEMPLATE_PATH,'template-schema.yml'
14
-
15
- # Creates a new *Validator* instance
16
- def initialize(template,schema=SCHEMA_FILE)
17
- @errors = []
18
- @template = template
19
- @schema = Loader.loadTemplate(schema)
20
- @types = @schema['types'] || {}
21
- end
22
-
23
- # Validates the template against the schema
24
- def validate()
25
- failed = []
26
-
27
- @schema['sections'].each{
28
- |section|
29
-
30
- #check required sections are there
31
- if (section['required'] && !@template.has_key?(section['name']))
32
- @errors.push('Error: missing required section - ' + section['name'])
33
- failed.push(section['name'])
34
- elsif @template.has_key?(section['name'])
35
- node = @template[section['name']]
36
- validated = match_node(node,section,section['name'])
37
- if(!validated)
38
- failed.push(section['name'])
39
- end
40
- end
41
-
42
- }
43
-
44
- puts 'Result: ' + (failed.empty? ? 'Validated Successfully!' : 'Validation Failed!')
45
-
46
- if !failed.empty? && !@errors.empty?
47
- puts 'Validation Failed with ' + @errors.count.to_s + ' errors';
48
- puts ''
49
- @errors.each{
50
- |error|
51
- puts error
52
- }
53
- return false
54
- else
55
- return true
56
- end
57
-
58
- end
59
-
60
- # Checks template node matches the schema.
61
- #
62
- # Checks type of node against expected type and
63
- # checks any children are of the accepted types.
64
- def match_node(node,expected,label)
65
-
66
- #check type
67
- if !check_type(node,expected['type'],label,expected['ok_empty'])
68
- return false
69
- end
70
-
71
- if (node.kind_of?(Hash) || node.kind_of?(Array))
72
-
73
- if node.empty? && !expected['ok_empty']
74
- @errors.push('Error: node ' + label + ' cannot be empty')
75
- return false
76
- elsif !node.empty? && expected.has_key?('accepts')
77
- valid_content = false
78
-
79
- if node.kind_of?(Hash)
80
- matched = []
81
- unmatched = []
82
- node.each_pair{
83
- |key,value|
84
-
85
- expected['accepts'].each{
86
- |accepts|
87
-
88
- result = check_type(value,accepts,key)
89
-
90
- if result
91
- matched.push(key)
92
- if !unmatched.find_index(key).nil?
93
- unmatched.slice(unmatched.find_index(key))
94
- end
95
- break
96
- else
97
- unmatched.push(key)
98
- end
99
-
100
- }
101
-
102
- }
103
-
104
- if(matched.count==node.count)
105
- valid_content = true
106
- else
107
- unmatched.each{
108
- |node|
109
-
110
- @errors.push('Error: node ' + node + ' is not of an accepted type. Should be one of ' + expected['accepts'].join(', '))
111
- }
112
- end
113
-
114
- elsif node.kind_of?(Array)
115
- matched = []
116
- unmatched = []
117
- node.each_index{
118
- |n|
119
-
120
- expected['accepts'].each{
121
- |accepts|
122
-
123
- key = label + '[' + n.to_s + ']'
124
- result = check_type(node[n],accepts,key)
125
-
126
- if result
127
-
128
- matched.push(key)
129
- if !unmatched.find_index(key).nil?
130
- unmatched.slice(unmatched.find_index(key))
131
- end
132
- break
133
- else
134
- unmatched.push(key)
135
- end
136
-
137
- }
138
- }
139
-
140
- if(matched.count==node.count)
141
- valid_content = true
142
- else
143
- unmatched.each{
144
- |node|
145
-
146
- @errors.push('Error: node ' + node + ' is not of an accepted type. Should be one of ' + expected['accepts'].join(', '))
147
- }
148
- end
149
-
150
- end
151
-
152
- if !valid_content
153
- @errors.push('Error: node ' + label + ' contains an unaccepted type.')
154
- return false
155
- end
156
- end
157
-
158
- end
159
-
160
- return true
161
-
162
- end
163
-
164
- # Checks that the node is of the correct type
165
- #
166
- # If the expected node is a custom node type as defined in the schema
167
- # It will run `match_node` to check that the node schema matches the
168
- # custom type.
169
- def check_type(node,expected_type,label,accept_nil = false)
170
-
171
- valid_type = true;
172
- if(@types.has_key?(expected_type))
173
- valid_type = match_node(node,@types[expected_type],label)
174
- elsif node.class.to_s != expected_type && !(node.kind_of?(NilClass) && (expected_type=='empty' || accept_nil))
175
- valid_type = false
176
- end
177
-
178
- return valid_type
179
-
180
- end
181
-
182
- end
183
-
184
- end
185
-
186
- end