yaml-validator 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaml-validator (0.1.0)
4
+ yaml-validator (0.1.1)
5
5
  colorize
6
6
  rake
7
7
  rspec
data/README.md CHANGED
@@ -40,3 +40,11 @@ nl.yml: parent_key.key1: missing variable 'var_with_typo' (available options var
40
40
 
41
41
  ```
42
42
 
43
+ Changelog
44
+ =========
45
+
46
+ 0.1.0
47
+ -----
48
+
49
+ * Added missing translations validation (strings that appear in en.yml but not in the other strings)
50
+
@@ -1,3 +1,3 @@
1
1
  class YamlValidator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -47,9 +47,11 @@ class YamlValidator
47
47
  return [e.message.sub(/^\([^)]+\)/, filename)]
48
48
  end
49
49
 
50
+ errors = validate_root_language(yaml_object, File.basename(filename))
51
+
50
52
  yaml_object = yaml_object[yaml_object.keys[0]]
51
53
  yaml_object = Helpers.normalize_yaml(yaml_object)
52
- errors = validate_yaml_object('', yaml_object)
54
+ errors += validate_yaml_object('', yaml_object)
53
55
  if @options[:show_missing]
54
56
  errors.concat find_missing_translations(yaml_object)
55
57
  end
@@ -57,6 +59,17 @@ class YamlValidator
57
59
  errors.map { |err| "#{filename}: #{err}" }
58
60
  end
59
61
 
62
+ def validate_root_language(yaml_object, file_name)
63
+ errors = []
64
+
65
+ lang = yaml_object.keys.first
66
+ if lang != file_name.split(".").first
67
+ errors << "invalid root language (#{lang})"
68
+ end
69
+
70
+ errors
71
+ end
72
+
60
73
  def validate_yaml_object(full_key, yaml_object)
61
74
  return [] if yaml_object.nil?
62
75
  errors = []
@@ -155,7 +168,7 @@ class YamlValidator
155
168
  end
156
169
 
157
170
  def identify_variables(string)
158
- string.scan(/%{([^}]+)}/).map { |v| v[0] }
171
+ string.scan(/%\{([^}]+)\}/).map(&:first)
159
172
  end
160
173
 
161
174
  end
@@ -0,0 +1,2 @@
1
+ en:
2
+ parent1: 'foo'
@@ -0,0 +1,2 @@
1
+ es:
2
+ parent1: 'foo'
@@ -78,7 +78,19 @@ describe YamlValidator do
78
78
  end
79
79
  end
80
80
 
81
-
81
+ describe "#validate_root_language" do
82
+ describe "file_name = he.yml, yaml_object = {es: parent1: 'foo'}" do
83
+ it "returns one error" do
84
+ validator = YamlValidator.new('spec/fixtures/wrong_root')
85
+ errors = validator.validate()
86
+ errors.should == [
87
+ "he.yml: invalid root language (es)",
88
+ ]
89
+
90
+ end
91
+ end
92
+ end
93
+
82
94
  describe "#validate_item" do
83
95
  describe "for 'parent1.key1' = 'hello %{name1}, %{day_of_week1}'" do
84
96
  it "returns two errors" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-07 00:00:00.000000000 Z
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -84,6 +84,8 @@ files:
84
84
  - spec/fixtures/invalid_yml/invalid.yml
85
85
  - spec/fixtures/missing_translations/en.yml
86
86
  - spec/fixtures/missing_translations/he.yml
87
+ - spec/fixtures/wrong_root/en.yml
88
+ - spec/fixtures/wrong_root/he.yml
87
89
  - spec/fixtures/wrong_variables/en.yml
88
90
  - spec/fixtures/wrong_variables/he.yml
89
91
  - spec/helpers_spec.rb
@@ -103,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
105
  version: '0'
104
106
  segments:
105
107
  - 0
106
- hash: 1734535970002030944
108
+ hash: 417878389105800096
107
109
  required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  none: false
109
111
  requirements:
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  version: '0'
113
115
  segments:
114
116
  - 0
115
- hash: 1734535970002030944
117
+ hash: 417878389105800096
116
118
  requirements: []
117
119
  rubyforge_project:
118
120
  rubygems_version: 1.8.24
@@ -126,6 +128,8 @@ test_files:
126
128
  - spec/fixtures/invalid_yml/invalid.yml
127
129
  - spec/fixtures/missing_translations/en.yml
128
130
  - spec/fixtures/missing_translations/he.yml
131
+ - spec/fixtures/wrong_root/en.yml
132
+ - spec/fixtures/wrong_root/he.yml
129
133
  - spec/fixtures/wrong_variables/en.yml
130
134
  - spec/fixtures/wrong_variables/he.yml
131
135
  - spec/helpers_spec.rb