grayskull 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/grayskull/formats.rb +6 -0
- data/lib/grayskull/formats/json_handler.rb +4 -0
- data/lib/grayskull/formats/yaml_handler.rb +4 -0
- data/lib/grayskull/validator.rb +6 -1
- data/lib/grayskull/version.rb +2 -1
- metadata +3 -4
- data/README +0 -0
data/lib/grayskull/formats.rb
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module Grayskull
|
2
2
|
|
3
|
+
# The *Formats* module contains handlers for all the supported formats and
|
4
|
+
# methods for format detection.
|
3
5
|
module Formats
|
4
6
|
|
5
7
|
autoload :YAMLHandler, 'grayskull/formats/yaml_handler'
|
6
8
|
autoload :JSONHandler, 'grayskull/formats/json_handler'
|
7
9
|
|
10
|
+
# Regular Expression to get file extension.
|
8
11
|
FILENAME_PATTERN = /(.+)\.([^\/\.]+)/
|
9
12
|
|
13
|
+
# Gets the file extension of the given file and returns the file format.
|
14
|
+
#
|
15
|
+
# Raises an exception if file is not of a valid type.
|
10
16
|
def self.detect_format(filename)
|
11
17
|
matches = FILENAME_PATTERN.match(filename.downcase).to_a
|
12
18
|
if matches
|
@@ -4,8 +4,12 @@ module Grayskull
|
|
4
4
|
|
5
5
|
module Formats
|
6
6
|
|
7
|
+
# Handler for JSON file format.
|
7
8
|
class JSONHandler
|
8
9
|
|
10
|
+
# Loads the JSON file and parses it into a ruby type.
|
11
|
+
#
|
12
|
+
# Raises an expection if file can not be parsed.
|
9
13
|
def self.load(file)
|
10
14
|
loaded = File.open(file)
|
11
15
|
content = loaded.gets nil
|
@@ -4,8 +4,12 @@ module Grayskull
|
|
4
4
|
|
5
5
|
module Formats
|
6
6
|
|
7
|
+
# Handler for YAML file format
|
7
8
|
class YAMLHandler
|
8
9
|
|
10
|
+
# Loads the YAML file and parses it into a ruby type.
|
11
|
+
#
|
12
|
+
# Raises an expection if file can not be parsed.
|
9
13
|
def self.load(file)
|
10
14
|
begin
|
11
15
|
return YAML.load_file(file)
|
data/lib/grayskull/validator.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module Grayskull
|
2
2
|
|
3
|
+
# The *Validator* class contains the core methods of the Grayskull library.
|
4
|
+
# It loads the passed files, converts them to Ruby types and validates them.
|
3
5
|
class Validator
|
4
6
|
|
7
|
+
# Creates a new *Validator* instance
|
5
8
|
def initialize(file,schema)
|
6
9
|
|
7
10
|
@file = file
|
@@ -14,6 +17,7 @@ module Grayskull
|
|
14
17
|
@errors = []
|
15
18
|
end
|
16
19
|
|
20
|
+
# Loads the specified file depending on the format
|
17
21
|
def load(file)
|
18
22
|
|
19
23
|
format = Formats::detect_format File.basename(file)
|
@@ -27,6 +31,7 @@ module Grayskull
|
|
27
31
|
|
28
32
|
end
|
29
33
|
|
34
|
+
# Validates the file against the schema
|
30
35
|
def validate()
|
31
36
|
failed = []
|
32
37
|
|
@@ -57,7 +62,7 @@ module Grayskull
|
|
57
62
|
return result
|
58
63
|
end
|
59
64
|
|
60
|
-
# Checks
|
65
|
+
# Checks file node matches the schema.
|
61
66
|
#
|
62
67
|
# Checks type of node against expected type and
|
63
68
|
# checks any children are of the accepted types.
|
data/lib/grayskull/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 3
|
9
|
+
version: 0.1.3
|
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-10-
|
17
|
+
date: 2011-10-02 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -53,7 +53,6 @@ extensions: []
|
|
53
53
|
extra_rdoc_files: []
|
54
54
|
|
55
55
|
files:
|
56
|
-
- README
|
57
56
|
- LICENSE
|
58
57
|
- lib/grayskull/cli.rb
|
59
58
|
- lib/grayskull/formats/json_handler.rb
|
data/README
DELETED
File without changes
|