messages_dictionary 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b4ac7e798bed0281aae5e9d5268d5ef6bbbc4c1
4
- data.tar.gz: 6b0f0b8d32d49aa64520afceb2fbea2f828c7885
3
+ metadata.gz: 006a1d75edd683d26bb9ffae6490e2820fc764d0
4
+ data.tar.gz: 53fac182dd60a6e5ed9fba049e540ab0e8c8546a
5
5
  SHA512:
6
- metadata.gz: e148950f11fe0156f3d4172e11347dd164fbb6a8864c2c1d546e1930eb0062f3072502e56212580b53f8bcfa7aef7ba614445cbf2f84ff1465538a4fd9cc3d98
7
- data.tar.gz: 908d398bcbf553537312123ef035fb5829a4af388089b106bb7a6fb8ddb9747198c491679683e9254d0af662e1974355c392e82121f5f633f52791a863e543b9
6
+ metadata.gz: 6fc44f71ab01840fbf419cf8b5f98dee6738e482d80454e4c81e43bc7f4740481f7d30bb8d7d0fecd7c0875d165895ddd158eea9ca34537be29c4c029c9bbc48
7
+ data.tar.gz: 7febb682b3f7b49f18a86b20da043fe1cfa5f7f840f9e5fa9e053d9eb22a47c7619c3dde4fd3eaad827c03a42dfb7f3b864f380d931f4707ad440f404076cf0e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messages_dictionary (0.0.2)
4
+ messages_dictionary (0.1.1)
5
5
  hashie (~> 3.4)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -4,22 +4,31 @@
4
4
  [![Code Climate](https://codeclimate.com/github/bodrovis-learning/messages_dictionary/badges/gpa.svg)](https://codeclimate.com/github/bodrovis-learning/messages_dictionary)
5
5
  [![Dependency Status](https://gemnasium.com/bodrovis-learning/messages_dictionary.svg)](https://gemnasium.com/bodrovis-learning/messages_dictionary)
6
6
 
7
- This gem was created as an educational project for my student. The idea behind this gem is to organize
7
+ This gem started as an educational project for my student. The idea behind this gem is to organize
8
8
  various messages in a simple key-value format that can be fetched later. Messages support interpolation,
9
9
  can be stored inside files or passed as hashes (nested hashes are supported as well). Custom fetching rules
10
10
  can be specified as well.
11
11
 
12
- Some use-cases can be found, for example, in the [Guesser](https://github.com/bodrovis/Guesser) game:
12
+ Install it
13
+
14
+ gem install messages_dictionary
15
+
16
+ and refer to the next sections to see it in action.
17
+
18
+ ## Use Cases
19
+
20
+ Wanna see it in action? Some use-cases can be found, in the [Guesser](https://github.com/bodrovis/Guesser) game:
13
21
 
14
22
  * [Messages are stored inside files](https://github.com/bodrovis/Guesser/tree/master/lib/guesser/messages)
15
23
  * [Displaying errors](https://github.com/bodrovis/Guesser/blob/master/lib/guesser.rb#L25)
16
24
  * [Displaying informational messages](https://github.com/bodrovis/Guesser/blob/master/lib/guesser/game.rb#L29)
17
25
 
18
- Install it
19
-
20
- gem install messages_dictionary
26
+ Another, a bit more complex, use case in the [lessons_indexer gem](https://github.com/bodrovis/lessons_indexer):
21
27
 
22
- and refer to the next section to see it in action.
28
+ * [Messages are stored in a single file](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer/messages/messages.yml)
29
+ * [Messenger class equipped with messages_dictionary magic is defined](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer.rb#L7)
30
+ * [Other classes simply inherit from it](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer/indexer.rb#L2)
31
+ * [Messages are fetched easily](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer/indexer.rb#L45)
23
32
 
24
33
  ## Usage
25
34
 
@@ -71,6 +80,8 @@ class MyOtherClass
71
80
 
72
81
  def greet
73
82
  pretty_output(:welcome)
83
+ # Or simply
84
+ pou(:welcome)
74
85
  end
75
86
  end
76
87
  ```
@@ -117,14 +128,14 @@ class MyClass
117
128
  has_messages_dictionary
118
129
 
119
130
  def do_something
120
- pretty_output('nested.value') # => 'Nested value'
131
+ pou('nested.value') # => 'Nested value'
121
132
  end
122
133
  end
123
134
  ```
124
135
 
125
136
  ### Indifferent Access
126
137
 
127
- Keys can be passed to the `pretty_output` method as symbols or strings - it does not really matter:
138
+ Keys can be passed to the `pou` method as symbols or strings - it does not really matter:
128
139
 
129
140
  ```ruby
130
141
  class MyClass
@@ -133,9 +144,9 @@ class MyClass
133
144
 
134
145
  def calculate(a)
135
146
  result = a ** 2
136
- pretty_output(:show_result, result: result)
147
+ pou(:show_result, result: result)
137
148
  # OR
138
- pretty_output('show_result', result: result)
149
+ pou('show_result', result: result)
139
150
  end
140
151
  end
141
152
  ```
@@ -199,7 +210,7 @@ class MyClass
199
210
  has_messages_dictionary
200
211
 
201
212
  def greet
202
- pretty_output(:welcome) do |msg|
213
+ pou(:welcome) do |msg|
203
214
  msg.upcase!
204
215
  end
205
216
  end
@@ -218,7 +229,7 @@ class MyClass
218
229
  has_messages_dictionary transform: ->(msg) {msg.upcase!}
219
230
 
220
231
  def greet
221
- pretty_output(:welcome)
232
+ pou(:welcome)
222
233
  end
223
234
  end
224
235
 
@@ -234,7 +245,7 @@ If you do want to output your message after transformation, you have to do it ex
234
245
 
235
246
  ```ruby
236
247
  def greet
237
- pretty_output(:welcome) do |msg|
248
+ pou(:welcome) do |msg|
238
249
  msg.upcase!
239
250
  puts msg # => Prints "WELCOME"
240
251
  end
@@ -32,6 +32,7 @@ module MessagesDictionary
32
32
  klass::DICTIONARY_CONF[:output].send(klass::DICTIONARY_CONF[:method].to_sym, msg)
33
33
  end
34
34
  private :pretty_output
35
+ alias_method :pou, :pretty_output
35
36
  end
36
37
  end
37
38
  end
@@ -1,3 +1,3 @@
1
1
  module MessagesDictionary
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -40,6 +40,17 @@ RSpec.describe MessagesDictionary do
40
40
  expect(output).to receive(:custom_puts).with('string')
41
41
  object.send(:pretty_output, :test)
42
42
  end
43
+
44
+ it "aliases pretty_output as pou" do
45
+ output = double('output')
46
+ @subject.class_eval do
47
+ has_messages_dictionary messages: {test: 'string'}, output: output
48
+ end
49
+
50
+ object = @subject.new
51
+ expect(output).to receive(:puts).with('string')
52
+ object.send(:pou, :test)
53
+ end
43
54
  end
44
55
 
45
56
  context "passed as hash" do
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "pry"
2
1
  require "codeclimate-test-reporter"
3
2
  CodeClimate::TestReporter.start
4
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messages_dictionary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Bodrov