tr8n_core 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -2
  3. data/lib/tr8n/api_client.rb +8 -0
  4. data/lib/tr8n/application.rb +8 -0
  5. data/lib/tr8n/base.rb +8 -0
  6. data/lib/tr8n/cache.rb +8 -0
  7. data/lib/tr8n/cache_adapters/cdb.rb +8 -0
  8. data/lib/tr8n/cache_adapters/file.rb +8 -0
  9. data/lib/tr8n/cache_adapters/memcache.rb +8 -0
  10. data/lib/tr8n/cache_adapters/redis.rb +9 -0
  11. data/lib/tr8n/component.rb +8 -0
  12. data/lib/tr8n/config.rb +8 -0
  13. data/lib/tr8n/decorators/base.rb +8 -0
  14. data/lib/tr8n/decorators/default.rb +8 -0
  15. data/lib/tr8n/decorators/html.rb +8 -0
  16. data/lib/tr8n/exception.rb +8 -0
  17. data/lib/tr8n/language.rb +8 -0
  18. data/lib/tr8n/language_case.rb +8 -0
  19. data/lib/tr8n/language_case_rule.rb +8 -0
  20. data/lib/tr8n/language_context.rb +8 -1
  21. data/lib/tr8n/language_context_rule.rb +8 -0
  22. data/lib/tr8n/logger.rb +8 -0
  23. data/lib/tr8n/rules_engine/evaluator.rb +8 -0
  24. data/lib/tr8n/rules_engine/parser.rb +8 -0
  25. data/lib/tr8n/session.rb +8 -0
  26. data/lib/tr8n/source.rb +8 -0
  27. data/lib/tr8n/tokens/data.rb +20 -14
  28. data/lib/tr8n/tokens/data_tokenizer.rb +8 -0
  29. data/lib/tr8n/tokens/decoration_tokenizer.rb +11 -22
  30. data/lib/tr8n/tokens/hidden.rb +8 -0
  31. data/lib/tr8n/tokens/method.rb +8 -0
  32. data/lib/tr8n/tokens/transform.rb +8 -0
  33. data/lib/tr8n/translation.rb +8 -0
  34. data/lib/tr8n/translation_key.rb +8 -0
  35. data/lib/tr8n/translator.rb +8 -0
  36. data/lib/tr8n/utils.rb +8 -0
  37. data/lib/tr8n_core/ext/array.rb +8 -0
  38. data/lib/tr8n_core/ext/date.rb +8 -0
  39. data/lib/tr8n_core/ext/fixnum.rb +8 -0
  40. data/lib/tr8n_core/ext/hash.rb +8 -0
  41. data/lib/tr8n_core/ext/string.rb +8 -0
  42. data/lib/tr8n_core/ext/time.rb +8 -0
  43. data/lib/tr8n_core/generators/cache/base.rb +8 -0
  44. data/lib/tr8n_core/generators/cache/cdb.rb +8 -0
  45. data/lib/tr8n_core/generators/cache/file.rb +8 -0
  46. data/lib/tr8n_core/version.rb +9 -2
  47. data/lib/tr8n_core.rb +9 -0
  48. data/spec/application_spec.rb +2 -2
  49. data/spec/cache/adapters/file_spec.rb +1 -1
  50. data/spec/cache/generators/file_generator_spec.rb +9 -9
  51. data/spec/config_spec.rb +3 -3
  52. data/spec/decorator_spec.rb +2 -0
  53. data/spec/ext/array_spec.rb +1 -1
  54. data/spec/ext/hash_spec.rb +1 -1
  55. data/spec/ext/string_spec.rb +1 -1
  56. data/spec/language_case_rule_spec.rb +8 -8
  57. data/spec/language_context_rule_spec.rb +16 -14
  58. data/spec/language_context_spec.rb +10 -8
  59. data/spec/language_spec.rb +1 -1
  60. data/spec/rules_engine/evaluator_spec.rb +52 -50
  61. data/spec/rules_engine/parser_spec.rb +2 -0
  62. data/spec/spec_helper.rb +7 -0
  63. data/spec/tokens/hidden_spec.rb +1 -1
  64. data/spec/tokens/method_spec.rb +4 -4
  65. data/spec/tokens/transform_spec.rb +4 -4
  66. data/spec/translation_key_spec.rb +1 -1
  67. data/spec/translation_spec.rb +1 -1
  68. metadata +3 -3
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Tr8n::RulesEngine::Evaluator do
@@ -14,13 +16,13 @@ describe Tr8n::RulesEngine::Evaluator do
14
16
  expect(e.evaluate(["cdr", ["+", 1, 2]])).to eq([1, 2])
15
17
  expect(e.evaluate(["cons", 1, ["quote", [2, 3]]])).to eq([1, 2, 3])
16
18
 
17
- expect(e.evaluate(["eq", 1, 1])).to be_true
19
+ expect(e.evaluate(["eq", 1, 1])).to be_truthy
18
20
 
19
- expect(e.evaluate(["atom", :a])).to be_true
20
- expect(e.evaluate(["atom", "hello"])).to be_true
21
- expect(e.evaluate(["atom", 1])).to be_true
22
- expect(e.evaluate(["atom", 1.4])).to be_true
23
- expect(e.evaluate(["atom", ["eq", 1, 1]])).to be_false
21
+ expect(e.evaluate(["atom", :a])).to be_truthy
22
+ expect(e.evaluate(["atom", "hello"])).to be_truthy
23
+ expect(e.evaluate(["atom", 1])).to be_truthy
24
+ expect(e.evaluate(["atom", 1.4])).to be_truthy
25
+ expect(e.evaluate(["atom", ["eq", 1, 1]])).to be_falsey
24
26
 
25
27
  expect(e.evaluate(["cond", ["eq", 1, 1], 1, 0])).to eq(1)
26
28
  expect(e.evaluate(["cond", ["eq", 1, 2], 1, 0])).to eq(0)
@@ -28,17 +30,17 @@ describe Tr8n::RulesEngine::Evaluator do
28
30
 
29
31
  it "evaluates rules" do
30
32
  e = Tr8n::RulesEngine::Evaluator.new
31
- expect(e.evaluate(["=", "1", "1"])).to be_true
32
- expect(e.evaluate(["=", "1", "2"])).to be_false
33
+ expect(e.evaluate(["=", "1", "1"])).to be_truthy
34
+ expect(e.evaluate(["=", "1", "2"])).to be_falsey
33
35
 
34
- expect(e.evaluate(["!=", "2", "1"])).to be_true
35
- expect(e.evaluate(["!=", "2", "2"])).to be_false
36
+ expect(e.evaluate(["!=", "2", "1"])).to be_truthy
37
+ expect(e.evaluate(["!=", "2", "2"])).to be_falsey
36
38
 
37
- expect(e.evaluate([">", "2", "1"])).to be_true
38
- expect(e.evaluate([">", "1", "2"])).to be_false
39
+ expect(e.evaluate([">", "2", "1"])).to be_truthy
40
+ expect(e.evaluate([">", "1", "2"])).to be_falsey
39
41
 
40
- expect(e.evaluate(["<", "2", "3"])).to be_true
41
- expect(e.evaluate(["<", "3", "2"])).to be_false
42
+ expect(e.evaluate(["<", "2", "3"])).to be_truthy
43
+ expect(e.evaluate(["<", "3", "2"])).to be_falsey
42
44
 
43
45
  expect(e.evaluate(["+", 1, 2])).to eq(3)
44
46
  expect(e.evaluate(["+", -1, 2])).to eq(1)
@@ -47,46 +49,46 @@ describe Tr8n::RulesEngine::Evaluator do
47
49
  expect(e.evaluate(["*", 2, 10])).to eq(20)
48
50
  expect(e.evaluate(["/", 20, 10])).to eq(2)
49
51
 
50
- expect(e.evaluate(["!", ["=", "1", "2"]])).to be_true
52
+ expect(e.evaluate(["!", ["=", "1", "2"]])).to be_truthy
51
53
 
52
- expect(e.evaluate(["&&", ["=", "1", "1"], ["=", 10, ["/", 20, 2]]])).to be_true
53
- expect(e.evaluate(["||", ["=", "2", "1"], ["=", 10, ["/", 20, 2]]])).to be_true
54
+ expect(e.evaluate(["&&", ["=", "1", "1"], ["=", 10, ["/", 20, 2]]])).to be_truthy
55
+ expect(e.evaluate(["||", ["=", "2", "1"], ["=", 10, ["/", 20, 2]]])).to be_truthy
54
56
 
55
57
  expect(e.evaluate(["if", ["=", 1, 2], 1, 0])).to eq(0)
56
58
 
57
59
  e.evaluate(["let", "@n", 1])
58
60
  expect(e.vars).to eq({"@n"=>1})
59
- expect(e.evaluate(["=", 1, "@n"])).to be_true
61
+ expect(e.evaluate(["=", 1, "@n"])).to be_truthy
60
62
 
61
63
  e.evaluate(["let", "@n", 11])
62
64
  expect(e.vars).to eq({"@n"=>11})
63
- expect(e.evaluate(["=", 11, "@n"])).to be_true
65
+ expect(e.evaluate(["=", 11, "@n"])).to be_truthy
64
66
 
65
- expect(e.evaluate(["and", ["=", "1", "1"], ["=", 10, ["/", 20, 2]]])).to be_true
66
- expect(e.evaluate(["or", ["=", "2", "1"], ["=", 10, ["/", 20, 2]]])).to be_true
67
+ expect(e.evaluate(["and", ["=", "1", "1"], ["=", 10, ["/", 20, 2]]])).to be_truthy
68
+ expect(e.evaluate(["or", ["=", "2", "1"], ["=", 10, ["/", 20, 2]]])).to be_truthy
67
69
 
68
70
  expect(e.evaluate(["mod", 23, 10])).to eq(3)
69
71
  expect(e.evaluate(["mod", 2.3, 10])).to eq(2.3)
70
72
 
71
- expect(e.evaluate(["match", "/hello/", "hello world"])).to be_true
72
- expect(e.evaluate(["match", "hello", "hello world"])).to be_true
73
- expect(e.evaluate(["match", "/^h/", "hello world"])).to be_true
74
- expect(e.evaluate(["match", "/^e/", "hello world"])).to be_false
75
- expect(e.evaluate(["match", "/^h.*d$/", "hello world"])).to be_true
73
+ expect(e.evaluate(["match", "/hello/", "hello world"])).to be_truthy
74
+ expect(e.evaluate(["match", "hello", "hello world"])).to be_truthy
75
+ expect(e.evaluate(["match", "/^h/", "hello world"])).to be_truthy
76
+ expect(e.evaluate(["match", "/^e/", "hello world"])).to be_falsey
77
+ expect(e.evaluate(["match", "/^h.*d$/", "hello world"])).to be_truthy
76
78
 
77
- expect(e.evaluate(["in", "1,2", "1"])).to be_true
78
- expect(e.evaluate(["in", "1,2", 1])).to be_true
79
- expect(e.evaluate(["in", "a,b,c", "a"])).to be_true
80
- expect(e.evaluate(["in", "a..c, d..z", "h"])).to be_true
79
+ expect(e.evaluate(["in", "1,2", "1"])).to be_truthy
80
+ expect(e.evaluate(["in", "1,2", 1])).to be_truthy
81
+ expect(e.evaluate(["in", "a,b,c", "a"])).to be_truthy
82
+ expect(e.evaluate(["in", "a..c, d..z", "h"])).to be_truthy
81
83
 
82
- expect(e.evaluate(["in", "1..5, 10..22", 21])).to be_true
83
- expect(e.evaluate(["in", "1..5, 10..22", 22])).to be_true
84
- expect(e.evaluate(["in", "1..5, 10..22", 1])).to be_true
85
- expect(e.evaluate(["in", "1..5, 10..22", 23])).to be_false
86
- expect(e.evaluate(["in", "1..5, 10..22", "9"])).to be_false
84
+ expect(e.evaluate(["in", "1..5, 10..22", 21])).to be_truthy
85
+ expect(e.evaluate(["in", "1..5, 10..22", 22])).to be_truthy
86
+ expect(e.evaluate(["in", "1..5, 10..22", 1])).to be_truthy
87
+ expect(e.evaluate(["in", "1..5, 10..22", 23])).to be_falsey
88
+ expect(e.evaluate(["in", "1..5, 10..22", "9"])).to be_falsey
87
89
 
88
- expect(e.evaluate(["within", "1..3", 2.3])).to be_true
89
- expect(e.evaluate(["within", "1..3", 3.3])).to be_false
90
+ expect(e.evaluate(["within", "1..3", 2.3])).to be_truthy
91
+ expect(e.evaluate(["within", "1..3", 3.3])).to be_falsey
90
92
 
91
93
  expect(e.evaluate(["replace", "/^hello/", "hi", "hello world"])).to eq("hi world")
92
94
  expect(e.evaluate(["replace", "world", "hi", "hello world"])).to eq("hello hi")
@@ -96,34 +98,34 @@ describe Tr8n::RulesEngine::Evaluator do
96
98
  expect(e.evaluate(["append", "world", "hello "])).to eq("hello world")
97
99
  expect(e.evaluate(["prepend", "hello ", "world"])).to eq("hello world")
98
100
 
99
- expect(e.evaluate(["true"])).to be_true
100
- expect(e.evaluate(["false"])).to be_false
101
+ expect(e.evaluate(["true"])).to be_truthy
102
+ expect(e.evaluate(["false"])).to be_falsey
101
103
 
102
104
  expect(e.evaluate(["date", "2011-01-01"])).to eq(Date.new(2011, 1, 1))
103
105
  expect(e.evaluate(["today"])).to eq(Date.today)
104
106
 
105
107
  expect(e.evaluate(["time", "2011-01-01 10:9:8"])).to eq(Time.new(2011, 1, 1, 10, 9, 8))
106
108
 
107
- expect(e.evaluate([">", ["date", "3014-01-01"], ["today"]])).to be_true
109
+ expect(e.evaluate([">", ["date", "3014-01-01"], ["today"]])).to be_truthy
108
110
  end
109
111
 
110
112
  it "evaluates expressions" do
111
113
  e = Tr8n::RulesEngine::Evaluator.new
112
114
 
113
115
  e.evaluate(["let", "@n", 1])
114
- expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_true
115
- expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_false
116
- expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_false
116
+ expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_truthy
117
+ expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_falsey
118
+ expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_falsey
117
119
 
118
120
  e.evaluate(["let", "@n", 21])
119
- expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_true
120
- expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_false
121
- expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_false
121
+ expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_truthy
122
+ expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_falsey
123
+ expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_falsey
122
124
 
123
125
  e.evaluate(["let", "@n", 11])
124
- expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_false
125
- expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_false
126
- expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_true
126
+ expect(e.evaluate(["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]])).to be_falsey
127
+ expect(e.evaluate(["&&", ["in", "2..4", ["mod", "@n", 10]], ["not", ["in", "12..14", ["mod", "@n", 100]]]])).to be_falsey
128
+ expect(e.evaluate(["||", ["=", 0, ["mod", "@n", 10]], ["in", "5..9", ["mod", "@n", 10]], ["in", "11..14", ["mod", "@n", 100]]])).to be_truthy
127
129
 
128
130
  rules = {
129
131
  "one" => ["&&", ["=", 1, ["mod", "@n", 10]], ["!=", 11, ["mod", "@n", 100]]],
@@ -138,7 +140,7 @@ describe Tr8n::RulesEngine::Evaluator do
138
140
  }.each do |key, values|
139
141
  values.each do |value|
140
142
  e.evaluate(["let", "@n", value])
141
- expect(e.evaluate(rules[key])).to be_true
143
+ expect(e.evaluate(rules[key])).to be_truthy
142
144
  end
143
145
  end
144
146
 
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Tr8n::RulesEngine::Parser do
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,13 @@ SimpleCov.start
14
14
 
15
15
  require 'tr8n_core'
16
16
 
17
+ RSpec.configure do |config|
18
+ config.raise_errors_for_deprecations!
19
+ config.mock_with :rspec do |c|
20
+ c.syntax = [:should, :expect]
21
+ end
22
+ end
23
+
17
24
  Tr8n.configure do |config|
18
25
  config.format = :text
19
26
  end
@@ -18,7 +18,7 @@ describe Tr8n::Tokens::Hidden do
18
18
  it "should parse data token" do
19
19
  expect(@token.class.name).to eq("Tr8n::Tokens::Hidden")
20
20
  expect(@token.context_keys).to eq([])
21
- expect(@token.allowed_in_translation?).to be_false
21
+ expect(@token.allowed_in_translation?).to be_falsey
22
22
  end
23
23
  end
24
24
  end
@@ -26,16 +26,16 @@ describe Tr8n::Tokens::Method do
26
26
  # expect(token.name_key).to eq(:"user.first_name")
27
27
  # expect(token.pipeless_name).to eq("user.first_name")
28
28
  # expect(token.case_key).to be_nil
29
- # expect(token.supports_cases?).to be_true
30
- # expect(token.has_case_key?).to be_false
29
+ # expect(token.supports_cases?).to be_truthy
30
+ # expect(token.has_case_key?).to be_falsey
31
31
  # expect(token.caseless_name).to eq("user.first_name")
32
32
  #
33
33
  # expect(token.types).to be_nil
34
- # expect(token.has_types?).to be_false
34
+ # expect(token.has_types?).to be_falsey
35
35
  # expect(token.associated_rule_types).to eq([:value])
36
36
  # expect(token.language_rule_classes).to eq([Tr8n::Rules::Value])
37
37
  # expect(token.transformable_language_rule_classes).to eq([])
38
- # expect(token.decoration?).to be_false
38
+ # expect(token.decoration?).to be_falsey
39
39
  # end
40
40
  #end
41
41
  #
@@ -26,16 +26,16 @@ describe Tr8n::Tokens::Transform do
26
26
  # expect(token.name_key).to eq(:count)
27
27
  # expect(token.pipeless_name).to eq("count")
28
28
  # expect(token.case_key).to be_nil
29
- # expect(token.supports_cases?).to be_true
30
- # expect(token.has_case_key?).to be_false
29
+ # expect(token.supports_cases?).to be_truthy
30
+ # expect(token.has_case_key?).to be_falsey
31
31
  # expect(token.caseless_name).to eq("count")
32
32
  #
33
33
  # expect(token.types).to be_nil
34
- # expect(token.has_types?).to be_false
34
+ # expect(token.has_types?).to be_falsey
35
35
  # expect(token.associated_rule_types).to eq([:number, :value])
36
36
  # expect(token.language_rule_classes).to eq([Tr8n::Rules::Number, Tr8n::Rules::Value])
37
37
  # expect(token.transformable_language_rule_classes).to eq([Tr8n::Rules::Number])
38
- # expect(token.decoration?).to be_false
38
+ # expect(token.decoration?).to be_falsey
39
39
  # end
40
40
  #end
41
41
  #
@@ -32,7 +32,7 @@ describe Tr8n::TranslationKey do
32
32
  expect(tkey.key).to eq("d541c79af1be6a05b1f16fca8b5730de")
33
33
  expect(tkey.locale).to eq("en-US")
34
34
  expect(tkey.language.locale).to eq("en-US")
35
- expect(tkey.has_translations_for_language?(@russian)).to be_false
35
+ expect(tkey.has_translations_for_language?(@russian)).to be_falsey
36
36
  expect(tkey.translations_for_language(@russian)).to eq([])
37
37
  end
38
38
 
@@ -16,7 +16,7 @@ describe Tr8n::Translation do
16
16
  t = Tr8n::Translation.new(:label => "You have {count||message}", :context => {"count" => {"number" => "one"}}, :language => @russian)
17
17
 
18
18
  [1, 101, 1001].each do |count|
19
- expect(t.matches_rules?(:count => count)).to be_true
19
+ expect(t.matches_rules?(:count => count)).to be_truthy
20
20
  end
21
21
 
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr8n_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Berkovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-09 00:00:00.000000000 Z
11
+ date: 2014-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: '0'
27
27
  description: Tr8n core classes that can be used by any Ruby framework
28
28
  email:
29
- - michael@translationexchange.com
29
+ - michael@tr8nhub.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []