rapporteur 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/CHANGELOG.md +8 -1
- data/lib/rapporteur/checker.rb +25 -5
- data/lib/rapporteur/message_list.rb +10 -7
- data/lib/rapporteur/version.rb +1 -1
- data/spec/models/message_list_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTAyZTdjMDkwMWE2NDczOTE5OTMxOGY2MTg0MDRlYTRmZGUyODQ3Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODNkYzI0ZWVjN2E1MDc3MTIwZDQ0NTNlMTJjMmVmODNiNzlhMDRjMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjBjOTBlYzU1NmU5ZDBhMzIxZjU1NTAxN2Q2NGZjNWY3YjU5YTVmNjliZGVj
|
10
|
+
YjkyY2IzOWIzMzRiYzQyM2RiZTU5MDQ2N2ZjZjhhZGI1OTM4YTg3YWQwMGMy
|
11
|
+
MWYwZWFmMTc3MDY4YmMyMWU2YTM2MGJlYzNlN2U4ZmJmNDZkNDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmNjZGY0Y2YwOGVkYzMzYmQ1MmYwZWRhMjNhMTJjNTJhZjk2NTU2ZGM0ZTg0
|
14
|
+
NDk2NjdhNzg5YjJjZTE2NGY2ZDkxYThjYWJjMGEzODhjZGZiMjM2ZjE4MWM1
|
15
|
+
ODNhNGViZTFiMTU3YWU1YzllYzM1YWRmZDI1ZGYxNmE3NmFjNTQ=
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
* No significant changes.
|
6
6
|
|
7
|
+
## [3.0.1][v3.0.1] / 2013-08-23
|
8
|
+
|
9
|
+
* Add back missing support for I18n interpolated values which was lost with the
|
10
|
+
customized message lists.
|
11
|
+
|
7
12
|
## [3.0.0][v3.0.0] / 2013-08-23
|
8
13
|
|
9
14
|
* Fix/add Ruby 1.8 compatibility. Because this library was built to work with
|
@@ -72,7 +77,9 @@
|
|
72
77
|
* Initial public release.
|
73
78
|
|
74
79
|
|
75
|
-
[unreleased]: https://github.com/codeschool/rapporteur/compare/
|
80
|
+
[unreleased]: https://github.com/codeschool/rapporteur/compare/v3.0.1...master
|
81
|
+
[v3.0.1]: https://github.com/codeschool/rapporteur/compare/v3.0.0...v3.0.1
|
82
|
+
[v3.0.0]: https://github.com/codeschool/rapporteur/compare/v2.1.0...v3.0.0
|
76
83
|
[v2.1.0]: https://github.com/codeschool/rapporteur/compare/v2.0.1...v2.1.0
|
77
84
|
[v2.0.1]: https://github.com/codeschool/rapporteur/compare/v2.0.0...v2.0.1
|
78
85
|
[v2.0.0]: https://github.com/codeschool/rapporteur/compare/v1.1.0...v2.0.0
|
data/lib/rapporteur/checker.rb
CHANGED
@@ -90,21 +90,34 @@ module Rapporteur
|
|
90
90
|
# is done with the pre-built checks. If you're using I18n, you'll need to
|
91
91
|
# define `rapporteur.errors.<your key>.<your message>`.
|
92
92
|
#
|
93
|
+
# name - A Symbol which indicates the attribute, name, or other identifier
|
94
|
+
# for the check being run.
|
95
|
+
# message - A String/Symbol/Proc to identify the message to provide in a
|
96
|
+
# check failure situation.
|
97
|
+
#
|
98
|
+
# A String is presented as given.
|
99
|
+
# A Symbol will attempt to translate through I18n or default to the String-form of the symbol.
|
100
|
+
# A Proc which will be called and the return value will be presented as returned.
|
101
|
+
# i18n_options - A Hash of options (likely variable key/value pairs) to
|
102
|
+
# pass to I18n during translation.
|
103
|
+
#
|
93
104
|
# Examples
|
94
105
|
#
|
95
106
|
# checker.add_error(:you, "failed.")
|
96
107
|
# checker.add_error(:using, :i18n_key_is_better)
|
108
|
+
# checker.add_error(:using, :i18n_with_variable, :custom_variable => 'pizza')
|
97
109
|
#
|
98
110
|
# en:
|
99
111
|
# rapporteur:
|
100
112
|
# errors:
|
101
113
|
# using:
|
102
114
|
# i18n_key_is_better: 'Look, localization!'
|
115
|
+
# i18n_with_variable: 'Look, %{custom_variable}!'
|
103
116
|
#
|
104
117
|
# Returns self.
|
105
118
|
#
|
106
|
-
def add_error(
|
107
|
-
@errors.add(
|
119
|
+
def add_error(name, message, i18n_options={})
|
120
|
+
@errors.add(name, message, i18n_options)
|
108
121
|
self
|
109
122
|
end
|
110
123
|
|
@@ -114,17 +127,24 @@ module Rapporteur
|
|
114
127
|
# name - A String containing the name or identifier for your message. This
|
115
128
|
# is unique and may be overriden by other checks using the name
|
116
129
|
# message name key.
|
117
|
-
#
|
130
|
+
#
|
131
|
+
# message - A String/Symbol/Proc containing the message to present to the
|
132
|
+
# user in a successful check sitaution.
|
133
|
+
#
|
134
|
+
# A String is presented as given.
|
135
|
+
# A Symbol will attempt to translate through I18n or default to the String-form of the symbol.
|
136
|
+
# A Proc which will be called and the return value will be presented as returned.
|
118
137
|
#
|
119
138
|
# Examples
|
120
139
|
#
|
121
140
|
# checker.add_message(:repository, 'git@github.com/user/repo.git')
|
122
141
|
# checker.add_message(:load, 0.934)
|
142
|
+
# checker.add_message(:load, :too_high, :measurement => '0.934')
|
123
143
|
#
|
124
144
|
# Returns self.
|
125
145
|
#
|
126
|
-
def add_message(name, message)
|
127
|
-
@messages.add(name, message)
|
146
|
+
def add_message(name, message, i18n_options={})
|
147
|
+
@messages.add(name, message, i18n_options)
|
128
148
|
self
|
129
149
|
end
|
130
150
|
|
@@ -45,17 +45,20 @@ module Rapporteur
|
|
45
45
|
#
|
46
46
|
# If a Proc is given, it is `.call`'d with no parameters. The
|
47
47
|
# return value from the Proc is directly used for the message.
|
48
|
+
# i18n_options - A Hash of optional key/value pairs to pass to the I18n
|
49
|
+
# translator.
|
48
50
|
#
|
49
51
|
# Examples
|
50
52
|
#
|
51
53
|
# list.add(:time, '2013-08-23T12:34:00Z')
|
52
54
|
# list.add(:time, :too_late)
|
55
|
+
# list.add(:time, :too_late, :time => 'midnight')
|
53
56
|
# list.add(:time, lambda { Time.now.iso8601 })
|
54
57
|
#
|
55
58
|
# Returns the MessageList instance.
|
56
59
|
#
|
57
|
-
def add(attribute, message)
|
58
|
-
@messages[attribute.to_sym].add(normalize_message(attribute, message))
|
60
|
+
def add(attribute, message, i18n_options = {})
|
61
|
+
@messages[attribute.to_sym].add(normalize_message(attribute, message, i18n_options))
|
59
62
|
self
|
60
63
|
end
|
61
64
|
|
@@ -108,17 +111,17 @@ module Rapporteur
|
|
108
111
|
private
|
109
112
|
|
110
113
|
|
111
|
-
def generate_message(key, type)
|
112
|
-
I18n.translate(type, {
|
114
|
+
def generate_message(key, type, i18n_options)
|
115
|
+
I18n.translate(type, i18n_options.merge({
|
113
116
|
:default => [type, type.to_s],
|
114
117
|
:scope => [:rapporteur, @list_type, key]
|
115
|
-
})
|
118
|
+
}))
|
116
119
|
end
|
117
120
|
|
118
|
-
def normalize_message(attribute, message)
|
121
|
+
def normalize_message(attribute, message, i18n_options)
|
119
122
|
case message
|
120
123
|
when Symbol
|
121
|
-
generate_message(attribute, message)
|
124
|
+
generate_message(attribute, message, i18n_options)
|
122
125
|
when Proc
|
123
126
|
message.call
|
124
127
|
else
|
data/lib/rapporteur/version.rb
CHANGED
@@ -33,6 +33,12 @@ describe Rapporteur::MessageList do
|
|
33
33
|
expect(list.full_messages).to include('test translated')
|
34
34
|
end
|
35
35
|
|
36
|
+
it 'translates and adds recognized I18n keys with named parameters in the #full_messages' do
|
37
|
+
add_translation(:errors, :test, :i18n_message, 'translated %{language}')
|
38
|
+
list.add(:test, :i18n_message, :language => 'French')
|
39
|
+
expect(list.full_messages).to include('test translated French')
|
40
|
+
end
|
41
|
+
|
36
42
|
it 'translates based on the initialized list type' do
|
37
43
|
add_translation(:string, :test, :i18n_message, 'strings')
|
38
44
|
add_translation(:messages, :test, :i18n_message, 'messages')
|