yaml-validator 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77d97bf3baf6728ffb9da7c658caa53775fbd621
4
- data.tar.gz: e8b5e202a428c260fe0978bf9ef1353cd39c677a
3
+ metadata.gz: c503fa73edea28c9fe2799bfaaf4758eca1b36ed
4
+ data.tar.gz: 60bef9cd8b188825561a14e8aeeb16fa38fb2ff1
5
5
  SHA512:
6
- metadata.gz: d19beeb8c9657d58c7c279e52d3b5e4c247a0a6639e789aa69851c9622cfce25eba4b72c6a1a2143801b30c47432bac2e7a9f72ba89b8fbf9e1fa9f38202ea8d
7
- data.tar.gz: 3ae273ea3a8a7b98f6a4a3a50b284038fb3adec9e115789a17161babba4427b8ea48bc57c046a8d663fd124e653c0f71a2deb02a3de03ac211f4d84ed6aea7ed
6
+ metadata.gz: 61c78d39bc78edd00f46e64e61518fc41f13a14c03006e3b1ed6503acf4f83e0ef2ef1b07a70e1494377f582869c9c8b3bece037a57ed58cf15ae7f359a093c5
7
+ data.tar.gz: b65227a65b0551438e3f6498cf095f60a7bcd26d1cd29a73295835f356339471bdfe98d6e00d3371a15d310649c42b3a7935db51cc1055a0f81606e8002544ec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaml-validator (0.1.7)
4
+ yaml-validator (0.1.8)
5
5
  colorize
6
6
  rake
7
7
  rspec
@@ -0,0 +1,31 @@
1
+ class LockedKeys
2
+ def initialize(root_path)
3
+ @locked_patterns = []
4
+
5
+ fullpath = File.join(root_path, 'locked_keys')
6
+ if File.exists? fullpath
7
+ read_locked_patterns(fullpath) unless File.directory?(fullpath)
8
+ end
9
+ end
10
+
11
+ def locked?(full_key)
12
+ @locked_patterns.each do |pattern|
13
+ if full_key =~ pattern
14
+ return true
15
+ end
16
+ end
17
+
18
+ false
19
+ end
20
+
21
+ private
22
+
23
+ def read_locked_patterns(fullpath)
24
+ File.open(fullpath) do |f|
25
+ f.each_line do |line|
26
+ next if line.empty? or line.start_with? '#'
27
+ @locked_patterns << Regexp.new(line.rstrip)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,21 +1,24 @@
1
+ # encoding: utf-8
1
2
  require 'yaml'
2
3
  require 'yaml-validator/version'
3
4
  require_relative './helpers'
4
5
  require_relative './pluralization-validator'
5
6
  require_relative './sanitized-html-validator'
7
+ require_relative './locked_keys'
6
8
 
7
9
  class YamlValidator
8
10
 
9
11
  def initialize(root_path, options = {})
10
12
  @options = options
11
13
  @root_path = root_path
14
+ @locked_keys = LockedKeys.new(@root_path) unless @root_path.nil?
12
15
  end
13
16
 
14
17
  def en
15
18
  return @en unless @en.nil?
16
19
 
17
20
  fullpath = File.join(@root_path, 'en.yml')
18
- return nil unless File.exists?(fullpath)
21
+ return nil unless File.readable?(fullpath)
19
22
 
20
23
  @en = YAML.load_file(fullpath)['en']
21
24
  @en = Helpers.normalize_yaml(@en)
@@ -135,9 +138,25 @@ class YamlValidator
135
138
  def validate_item(full_key, value, is_pluralization = false)
136
139
  errors = validate_item_vars(full_key, value, is_pluralization)
137
140
  errors.concat validate_item_characters(full_key, value)
141
+ errors.concat validate_locked_key(full_key, value)
138
142
  errors
139
143
  end
140
144
 
145
+ def validate_locked_key(full_key, value)
146
+ errors = []
147
+ if @locked_keys.locked? full_key
148
+ locked_value = find_english_value(full_key)
149
+ if locked_value != value
150
+ errors << "#{full_key}: locked key value changed from '#{locked_value}' to '#{value}'"
151
+ end
152
+ end
153
+ errors
154
+ end
155
+
156
+ def find_english_value(full_key)
157
+ self.class.find_key_in_yaml_object(full_key, en)
158
+ end
159
+
141
160
  def validate_item_characters(full_key, value)
142
161
  bad_chars = '⏎'
143
162
  bad_chars_found = []
@@ -1,3 +1,3 @@
1
1
  class YamlValidator
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1,15 @@
1
+ en:
2
+ key1: value
3
+ locked_key1: locked value
4
+ locked_key2: locked value
5
+ locked_key3: locked value
6
+ unlocked_key4: locked value
7
+ key3:
8
+ subkey1: value
9
+ locked_subkey1: locked value
10
+ locked_subkey2: locked value
11
+ items:
12
+ - locked_key1: locked value
13
+ unlocked_key1: bla bla
14
+ - locked_key1: locked value
15
+
@@ -0,0 +1,15 @@
1
+ es:
2
+ key1: different value
3
+ locked_key1: locked value
4
+ locked_key2: changed value
5
+ locked_key3: changed value
6
+ unlocked_key4: changed value
7
+ key3:
8
+ subkey1: value
9
+ locked_subkey1: changed value
10
+ locked_subkey2: changed value
11
+ items:
12
+ - locked_key1: changed value
13
+ unlocked_key1: changed value
14
+ - locked_key1: changed value
15
+
@@ -0,0 +1,4 @@
1
+ ^locked_key[0-9]
2
+ key3.locked_subkey1
3
+ locked_subkey2
4
+ items.[0-9]+.locked_key
@@ -35,6 +35,21 @@ describe YamlValidator do
35
35
  end
36
36
  end
37
37
 
38
+ describe "locked_keys scenario" do
39
+ it "returns errors" do
40
+ validator = YamlValidator.new('spec/fixtures/locked_keys', missing: false)
41
+ errors = validator.validate()
42
+ errors.should == [
43
+ "es.yml: locked_key2: locked key value changed from 'locked value' to 'changed value'",
44
+ "es.yml: locked_key3: locked key value changed from 'locked value' to 'changed value'",
45
+ "es.yml: key3.locked_subkey1: locked key value changed from 'locked value' to 'changed value'",
46
+ "es.yml: key3.locked_subkey2: locked key value changed from 'locked value' to 'changed value'",
47
+ "es.yml: items.0.locked_key1: locked key value changed from 'locked value' to 'changed value'",
48
+ "es.yml: items.1.locked_key1: locked key value changed from 'locked value' to 'changed value'"
49
+ ]
50
+ end
51
+ end
52
+
38
53
  describe "bad_chars scenario" do
39
54
  it "returns two errors" do
40
55
  validator = YamlValidator.new('spec/fixtures/bad_chars')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Elentok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-01 00:00:00.000000000 Z
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - bin/yaml-validator
99
99
  - lib/helpers.rb
100
+ - lib/locked_keys.rb
100
101
  - lib/pluralization-validator.rb
101
102
  - lib/sanitized-html-validator.rb
102
103
  - lib/yaml-validator.rb
@@ -109,6 +110,9 @@ files:
109
110
  - spec/fixtures/inconsistent_types/he.yml
110
111
  - spec/fixtures/invalid_yml/en.yml
111
112
  - spec/fixtures/invalid_yml/invalid.yml
113
+ - spec/fixtures/locked_keys/en.yml
114
+ - spec/fixtures/locked_keys/es.yml
115
+ - spec/fixtures/locked_keys/locked_keys
112
116
  - spec/fixtures/missing_translations/en.yml
113
117
  - spec/fixtures/missing_translations/he.yml
114
118
  - spec/fixtures/numbered_keys/en.yml
@@ -153,6 +157,9 @@ test_files:
153
157
  - spec/fixtures/inconsistent_types/he.yml
154
158
  - spec/fixtures/invalid_yml/en.yml
155
159
  - spec/fixtures/invalid_yml/invalid.yml
160
+ - spec/fixtures/locked_keys/en.yml
161
+ - spec/fixtures/locked_keys/es.yml
162
+ - spec/fixtures/locked_keys/locked_keys
156
163
  - spec/fixtures/missing_translations/en.yml
157
164
  - spec/fixtures/missing_translations/he.yml
158
165
  - spec/fixtures/numbered_keys/en.yml