yml_validator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ff2866a73704ed414533666ff72b5000824a544
4
+ data.tar.gz: b8df74a9dacc65e0e4e7b88dd0b0306bb6ae0af8
5
+ SHA512:
6
+ metadata.gz: 63fb27872dc2f322ebf3cc18aef3e5a8bafcf4202b71c7a84d43901dd8dfc841efecd16ced1e7e5e545754432fe6f52b9fd9ee0dc5176699914dc41e9a5e62f6
7
+ data.tar.gz: ccf481dd41abd1618e6d28049cec02d0f7867c6beee70c57a3b618a8d3654ba2ca3b162f315e8467d52e941c1a40b68c114150215ee2b5fa58362f287e105f97
@@ -0,0 +1,2 @@
1
+ /pkg
2
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yml_validator (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.1.0)
12
+ rspec-core (~> 3.1.0)
13
+ rspec-expectations (~> 3.1.0)
14
+ rspec-mocks (~> 3.1.0)
15
+ rspec-core (3.1.4)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-expectations (3.1.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.1.0)
20
+ rspec-mocks (3.1.1)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-support (3.1.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rake
29
+ rspec
30
+ yml_validator!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Ģirts Ķesteris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,16 @@
1
+ ## Usage
2
+
3
+ Via object ->
4
+ @yml_validator = YMLValidator.new "spec/fixtures/binary.yml"
5
+ @yml_validator.valid?
6
+
7
+ Oneliner ->
8
+ YMLValidator.valid? "spec/fixtures/binary.yml"
9
+
10
+ ## Contribution
11
+
12
+ 1. Fork it ( https://github.com/Sacristan/yml_validator/fork )
13
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
14
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
15
+ 4. Push to the branch (`git push origin my-new-feature`)
16
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rdoc/task'
3
+
4
+ require "bundler/gem_tasks"
5
+ require "rspec/core/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: :spec
10
+ task test: :spec
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+ require 'yml_validator/base'
3
+ require 'yml_validator/helpers'
4
+ require 'yml_validator/version'
5
+
6
+ module YMLValidator
7
+ def self.new file_path
8
+ YMLValidator::Base.new file_path
9
+ end
10
+
11
+ def self.valid? file_path
12
+ YMLValidator.new(file_path).valid?
13
+ end
14
+
15
+ end
@@ -0,0 +1,27 @@
1
+ module YMLValidator
2
+ class Base
3
+ attr_accessor :file_path
4
+ attr_accessor :file_to_validate
5
+ attr_accessor :normalized_file
6
+
7
+ def initialize file_path
8
+ @file_path = file_path
9
+ end
10
+
11
+ def valid?
12
+ begin
13
+ @file_to_validate = YAML.load_file(@file_path)
14
+ rescue Psych::SyntaxError => e
15
+ return false
16
+ end
17
+
18
+ validate
19
+ end
20
+
21
+ private
22
+ def validate
23
+ @normalized_file = YMLValidator::Helpers.normalize_yaml @file_to_validate
24
+ @normalized_file.is_a?(Hash) && !!@normalized_file.to_yaml
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module YMLValidator
2
+ module Helpers
3
+ def self.normalize_yaml yaml
4
+ return '' if yaml.nil?
5
+ return yaml if yaml.is_a? String
6
+ return yaml.to_s if yaml.is_a? Numeric
7
+ return yaml.to_s if !!yaml == yaml # if boolean
8
+ return ":#{yaml.to_s}" if yaml.is_a? Symbol
9
+ yaml = array_to_hash(yaml) if yaml.is_a? Array
10
+
11
+ normalized = {}
12
+ yaml.each do |key, value|
13
+ normalized[key.to_s] = normalize_yaml(value)
14
+ end
15
+ normalized
16
+ end
17
+
18
+ private
19
+ def self.array_to_hash(array)
20
+ hash = {}
21
+ array.each_with_index { |val, i| hash[i.to_s] = val }
22
+ hash
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module YMLValidator
2
+ VERSION = "0.1.0"
3
+ end
Binary file
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Application
@@ -0,0 +1,13 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: dev
4
+ host: localhost
5
+ username: user
6
+ password:
7
+
8
+ test:
9
+ adapter: postgresql
10
+ database: test
11
+ host: localhost
12
+ username: user
13
+ password:
@@ -0,0 +1 @@
1
+ Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
@@ -0,0 +1,13 @@
1
+ development:
2
+ adapter: postgresql
3
+ database: dev
4
+ host: localhost
5
+ username: user
6
+ password:
7
+
8
+ test:
9
+ adapter: postgresql
10
+ database: test
11
+ host: localhost
12
+ username: user
13
+ password:
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require "yml_validator"
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
@@ -0,0 +1,68 @@
1
+ # rspec spec/tests/validate_using_instance_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "ValidateUsingInstance" do
6
+ context "valid?" do
7
+ context "should return false for " do
8
+ context "binary file" do
9
+ before :all do
10
+
11
+ @yml_validator = YMLValidator.new "spec/fixtures/binary.yml"
12
+ end
13
+ it "" do
14
+ expect(@yml_validator.valid?).to eq false
15
+ end
16
+
17
+ end
18
+
19
+ context "RoR config_file" do
20
+ before :all do
21
+
22
+ @yml_validator = YMLValidator.new "spec/fixtures/conf_file.yml"
23
+ end
24
+ it "" do
25
+ expect(@yml_validator.valid?).to eq false
26
+ end
27
+
28
+ end
29
+
30
+ context "plain text" do
31
+ before :all do
32
+
33
+ @yml_validator = YMLValidator.new "spec/fixtures/plain_text.yml"
34
+ end
35
+ it "" do
36
+ expect(@yml_validator.valid?).to eq false
37
+ end
38
+
39
+ end
40
+
41
+ context "invalid yml" do
42
+ before :all do
43
+
44
+ @yml_validator = YMLValidator.new "spec/fixtures/invalid_yaml.yml"
45
+ end
46
+ it "" do
47
+ expect(@yml_validator.valid?).to eq false
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ context "should return true for" do
54
+ context "valid yml" do
55
+ before :all do
56
+
57
+ @yml_validator = YMLValidator.new "spec/fixtures/valid_yml.yml"
58
+ end
59
+
60
+ it "" do
61
+ expect(@yml_validator.valid?).to eq true
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,47 @@
1
+ # rspec spec/tests/validate_using_module_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "ValidateUsingModule" do
6
+ context "valid?" do
7
+ context "should return false for " do
8
+ context "binary file" do
9
+ it "" do
10
+ expect(YMLValidator.valid? "spec/fixtures/binary.yml").to eq false
11
+ end
12
+
13
+ end
14
+
15
+ context "RoR config_file" do
16
+
17
+ it "" do
18
+ expect(YMLValidator.valid? "spec/fixtures/conf_file.yml").to eq false
19
+ end
20
+
21
+ end
22
+
23
+ context "plain text" do
24
+ it "" do
25
+ expect(YMLValidator.valid? "spec/fixtures/plain_text.yml").to eq false
26
+ end
27
+
28
+ end
29
+
30
+ context "invalid yml" do
31
+ it "" do
32
+ expect(YMLValidator.valid? "spec/fixtures/invalid_yaml.yml").to eq false
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ context "should return true for" do
39
+ context "valid yml" do
40
+ it "" do
41
+ expect(YMLValidator.valid? "spec/fixtures/valid_yml.yml").to eq true
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'yml_validator'
4
+ require "yml_validator/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "yml_validator"
8
+ s.version = YMLValidator::VERSION
9
+ s.author = "Girts Kesteris"
10
+ s.email = ["girts.kesteris@gmail.com"]
11
+ s.homepage = "https://github.com/Sacristan/yml_validator"
12
+ s.platform = Gem::Platform::RUBY
13
+ s.summary = "Simple YML validation"
14
+ s.require_path = "lib"
15
+ s.has_rdoc = false
16
+ s.extra_rdoc_files = ["README.rdoc"]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.license = 'MIT'
22
+ s.require_paths = ["lib"]
23
+ s.rubyforge_project = "yml_validator"
24
+
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec'
27
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yml_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Girts Kesteris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - girts.kesteris@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.rdoc
48
+ files:
49
+ - .gitignore
50
+ - .rspec
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.rdoc
55
+ - Rakefile
56
+ - lib/yml_validator.rb
57
+ - lib/yml_validator/base.rb
58
+ - lib/yml_validator/helpers.rb
59
+ - lib/yml_validator/version.rb
60
+ - spec/fixtures/binary.yml
61
+ - spec/fixtures/conf_file.yml
62
+ - spec/fixtures/invalid_yaml.yml
63
+ - spec/fixtures/plain_text.yml
64
+ - spec/fixtures/valid_yml.yml
65
+ - spec/spec_helper.rb
66
+ - spec/tests/validate_using_instance_spec.rb
67
+ - spec/tests/validate_using_module_spec.rb
68
+ - yml_validator.gemspec
69
+ homepage: https://github.com/Sacristan/yml_validator
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: yml_validator
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Simple YML validation
93
+ test_files:
94
+ - spec/fixtures/binary.yml
95
+ - spec/fixtures/conf_file.yml
96
+ - spec/fixtures/invalid_yaml.yml
97
+ - spec/fixtures/plain_text.yml
98
+ - spec/fixtures/valid_yml.yml
99
+ - spec/spec_helper.rb
100
+ - spec/tests/validate_using_instance_spec.rb
101
+ - spec/tests/validate_using_module_spec.rb