messages_dictionary 1.0.0 → 2.1.0

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
- SHA1:
3
- metadata.gz: 8553f6876fbb84b53888586d0405beb076319f63
4
- data.tar.gz: f2ffe53351402204f081421bc303d606633e5263
2
+ SHA256:
3
+ metadata.gz: 3a6f7d3a4a63be59119844b7d3139f10b82118a7a726cbfb59f078dc68edb916
4
+ data.tar.gz: 1884503b8aad4f2c452666833a7a48867c2c0fa55c74854e94ea0a5a6c0bed79
5
5
  SHA512:
6
- metadata.gz: 4c2cf012d57620c0f2a904743bc9b40b57a509102c0d9b2876561e42cb8f1745cf8a332eca8047b416f7ae10cf0a50d316dd229a063050a6aa27903fde60372e
7
- data.tar.gz: 6e7351eb3989b960a5238a496649dd917049dc95f973326a2cfa9635162e88aadb7083609e130c1814fd3c47864156e8fe4052e3d0a3ca18a232cf74fa672552
6
+ metadata.gz: 2979cbdfacfdfdd47985304f3d6535ce4fe121ca240807e1700a8f9a15aa54e4301e487eeddbcaf9f456f4814f0f51d881e026cdafd65a23ce96d3c539b29057
7
+ data.tar.gz: eb7c8163836c469604d4fb1af38c84fc9c4d3a450dba73cb429e018a741e55768b0b25fa4f6be2715157e9ec794daf31bd21505db0179f9fe84f23b75cd289d6
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at golosizpru@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,14 @@
1
+ # Contributing
2
+
3
+ 1. [Fork the repository.][fork]
4
+ 2. [Create a topic branch.][branch]
5
+ 3. Implement your feature or bug fix.
6
+ 4. Don't forget to add specs and make sure they pass by running `rspec .`.
7
+ 5. Make sure your code complies with the style guide by running `rubocop`. `rubocop -a` can automatically fix most issues for you. Run `rubocop -A` to make it more aggressive.
8
+ 6. If necessary, add documentation for your feature or bug fix.
9
+ 7. Commit and push your changes.
10
+ 8. [Submit a pull request.][pr]
11
+
12
+ [fork]: http://help.github.com/fork-a-repo/
13
+ [branch]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-branches
14
+ [pr]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees: bodrovis
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior.
15
+
16
+ **Expected behavior**
17
+ A clear and concise description of what you expected to happen.
18
+
19
+ **Your environment:**
20
+ - OS
21
+ - Ruby version
22
+
23
+ **Additional context**
24
+ Add any other context about the problem here.
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: bodrovis
7
+
8
+ ---
9
+
10
+ **The feature I'd like is...**
11
+
12
+ **Additional context**
13
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,11 @@
1
+ ### Summary
2
+
3
+ Provide a general description of the code changes in your pull
4
+ request. Were there any bugs you had fixed? If so, mention them. If
5
+ these bugs have open GitHub issues, be sure to tag them here as well,
6
+ to keep the conversation linked together.
7
+
8
+ ### Other Information
9
+
10
+ If there's anything else that's important and relevant to your pull
11
+ request, mention that information here.
@@ -0,0 +1,11 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "bundler" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "monthly"
@@ -0,0 +1,27 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ push:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ os: [ubuntu-latest]
15
+ ruby:
16
+ - 2.7
17
+ - '3.0'
18
+ - 3.1
19
+ runs-on: ${{ matrix.os }}
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
27
+ - run: bundle exec rake rubospec
data/.gitignore CHANGED
@@ -1,5 +1,13 @@
1
- # RubyMine config files
2
- .idea/
1
+ .idea/*
3
2
  *.gem
3
+ coverage/*
4
4
  Gemfile.lock
5
- coverage/
5
+ *~
6
+ .bundle
7
+ .rvmrc
8
+ log/*
9
+ measurement/*
10
+ pkg/*
11
+ .DS_Store
12
+ .env
13
+ demo.rb
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ - rubocop-rake
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.7
8
+ NewCops: enable
9
+
10
+ Layout/SpaceInsideHashLiteralBraces:
11
+ EnforcedStyle: no_space
12
+
13
+ Metrics/BlockLength:
14
+ Max: 36
15
+ Exclude:
16
+ - spec/**/*.rb
17
+ - rating-chgk-v2.gemspec
18
+
19
+ Metrics/BlockNesting:
20
+ Max: 2
21
+
22
+ Metrics/MethodLength:
23
+ CountComments: false
24
+ Max: 10
25
+
26
+ Style/CollectionMethods:
27
+ Enabled: true
28
+ PreferredMethods:
29
+ collect: 'map'
30
+ collect!: 'map!'
31
+ inject: 'reduce'
32
+ find: 'detect'
33
+ find_all: 'select'
34
+ delete: 'gsub'
35
+
36
+ Layout/DotPosition:
37
+ EnforcedStyle: trailing
38
+
39
+ RSpec/MultipleExpectations:
40
+ Max: 10
41
+
42
+ RSpec/ExampleLength:
43
+ Max: 35
44
+
45
+ RSpec/MessageSpies:
46
+ EnforcedStyle: have_received
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ ## 2.1.0 (22-Nov-2022)
4
+
5
+ * `pou` and `pretty_output` are now available inside class methods
6
+ * `DICTIONARY_CONF` now contains an instance of the `Config` class that takes care of all configuration options
7
+ * Added `lazy` option that enables lazy loading
8
+ * Added `on_key_missing` option which is set to `:raise` by default. You can pass a proc or a lambda to this option in order to provide a custom handler that fires when a given key cannot be found.
9
+ * Added `file_loader` option to handle custom file loading
10
+
11
+ ## 2.0.0 (21-Nov-2022)
12
+
13
+ This is a major re-write of the gem. All core features stay the same and there should not be any breaking changes, except for one thing: you should not use "destructive" methods when transforming your messages.
14
+
15
+ Previously you could say:
16
+
17
+ ```ruby
18
+ def greet
19
+ pou(:welcome) do |msg|
20
+ puts msg.upcase!
21
+ end
22
+ end
23
+ ```
24
+
25
+ Now it's recommended to use "safe" `upcase` method:
26
+
27
+ ```ruby
28
+ def greet
29
+ pou(:welcome) do |msg|
30
+ puts msg.upcase
31
+ end
32
+ end
33
+ ```
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- gemspec
5
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,46 +1,84 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messages_dictionary (1.0.0)
5
- hashie (~> 3.4)
4
+ messages_dictionary (2.1.0)
5
+ hashie (~> 5.0)
6
+ zeitwerk (~> 2.4)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- codeclimate-test-reporter (1.0.8)
11
- simplecov (<= 0.13)
12
- diff-lcs (1.3)
13
- docile (1.1.5)
14
- hashie (3.5.5)
15
- json (2.1.0)
16
- rake (12.0.0)
17
- rspec (3.6.0)
18
- rspec-core (~> 3.6.0)
19
- rspec-expectations (~> 3.6.0)
20
- rspec-mocks (~> 3.6.0)
21
- rspec-core (3.6.0)
22
- rspec-support (~> 3.6.0)
23
- rspec-expectations (3.6.0)
11
+ ast (2.4.2)
12
+ codecov (0.6.0)
13
+ simplecov (>= 0.15, < 0.22)
14
+ diff-lcs (1.5.0)
15
+ docile (1.4.0)
16
+ hashie (5.0.0)
17
+ json (2.6.2)
18
+ parallel (1.22.1)
19
+ parser (3.1.2.1)
20
+ ast (~> 2.4.1)
21
+ rainbow (3.1.1)
22
+ rake (13.0.6)
23
+ regexp_parser (2.6.1)
24
+ rexml (3.2.5)
25
+ rspec (3.12.0)
26
+ rspec-core (~> 3.12.0)
27
+ rspec-expectations (~> 3.12.0)
28
+ rspec-mocks (~> 3.12.0)
29
+ rspec-core (3.12.0)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-expectations (3.12.0)
24
32
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.6.0)
26
- rspec-mocks (3.6.0)
33
+ rspec-support (~> 3.12.0)
34
+ rspec-mocks (3.12.0)
27
35
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.6.0)
29
- rspec-support (3.6.0)
30
- simplecov (0.13.0)
31
- docile (~> 1.1.0)
32
- json (>= 1.8, < 3)
33
- simplecov-html (~> 0.10.0)
34
- simplecov-html (0.10.0)
36
+ rspec-support (~> 3.12.0)
37
+ rspec-support (3.12.0)
38
+ rubocop (1.39.0)
39
+ json (~> 2.3)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.1.2.1)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml (>= 3.2.5, < 4.0)
45
+ rubocop-ast (>= 1.23.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 3.0)
48
+ rubocop-ast (1.23.0)
49
+ parser (>= 3.1.1.0)
50
+ rubocop-performance (1.15.1)
51
+ rubocop (>= 1.7.0, < 2.0)
52
+ rubocop-ast (>= 0.4.0)
53
+ rubocop-rake (0.6.0)
54
+ rubocop (~> 1.0)
55
+ rubocop-rspec (2.15.0)
56
+ rubocop (~> 1.33)
57
+ ruby-progressbar (1.11.0)
58
+ simplecov (0.21.2)
59
+ docile (~> 1.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov_json_formatter (~> 0.1)
62
+ simplecov-html (0.12.3)
63
+ simplecov_json_formatter (0.1.4)
64
+ unicode-display_width (2.3.0)
65
+ zeitwerk (2.6.6)
35
66
 
36
67
  PLATFORMS
37
- ruby
68
+ x64-mingw-ucrt
69
+ x86_64-linux
38
70
 
39
71
  DEPENDENCIES
40
- codeclimate-test-reporter (~> 1.0)
72
+ codecov (~> 0.1)
73
+ json (~> 2)
41
74
  messages_dictionary!
42
- rake (~> 12.0)
75
+ rake (~> 13.0)
43
76
  rspec (~> 3.6)
77
+ rubocop (~> 1.6)
78
+ rubocop-performance (~> 1.5)
79
+ rubocop-rake (~> 0.6)
80
+ rubocop-rspec (~> 2.0)
81
+ simplecov (~> 0.16)
44
82
 
45
83
  BUNDLED WITH
46
- 1.14.6
84
+ 2.3.26
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 Ilya Bodrov
1
+ Copyright 2016 Ilya Krukowski
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # MessagesDictionary
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/messages_dictionary.svg)](https://badge.fury.io/rb/messages_dictionary)
3
- [![Build Status](https://travis-ci.org/bodrovis-learning/messages_dictionary.svg?branch=master)](https://travis-ci.org/bodrovis-learning/messages_dictionary)
4
- [![Code Climate](https://codeclimate.com/github/bodrovis-learning/messages_dictionary/badges/gpa.svg)](https://codeclimate.com/github/bodrovis-learning/messages_dictionary)
5
- [![Dependency Status](https://gemnasium.com/bodrovis-learning/messages_dictionary.svg)](https://gemnasium.com/bodrovis-learning/messages_dictionary)
4
+ ![CI](https://github.com/bodrovis-learning/messages_dictionary/actions/workflows/ci.yml/badge.svg)
5
+ [![Test Coverage](https://codecov.io/gh/bodrovis-learning/messages_dictionary/graph/badge.svg)](https://codecov.io/gh/bodrovis-learning/messages_dictionary)
6
+ ![Downloads total](https://img.shields.io/gem/dt/messages_dictionary)
6
7
 
7
8
  This gem started as an educational project for my student. The idea behind this gem is to organize
8
9
  various messages in a simple key-value format that can be fetched later. Messages support interpolation,
@@ -11,11 +12,13 @@ can be specified as well.
11
12
 
12
13
  [Here is my article](https://www.sitepoint.com/learn-ruby-metaprogramming-for-great-good/) describing how this gem was actually written.
13
14
 
14
- Install it
15
+ This gem requires Ruby 2.7+. Install it by running:
15
16
 
16
- gem install messages_dictionary
17
+ ```
18
+ gem install messages_dictionary
19
+ ```
17
20
 
18
- and refer to the next sections to see it in action.
21
+ Refer to the next sections to see it in action.
19
22
 
20
23
  ## Use Cases
21
24
 
@@ -32,9 +35,7 @@ Another, a bit more complex, use case in the [lessons_indexer gem](https://githu
32
35
  * [Other classes simply inherit from it](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer/indexer.rb#L2)
33
36
  * [Messages are fetched easily](https://github.com/bodrovis/lessons_indexer/blob/master/lib/lessons_indexer/indexer.rb#L45)
34
37
 
35
- ## Usage
36
-
37
- ### Basic Example
38
+ ## Basic usage
38
39
 
39
40
  Suppose you have the following program:
40
41
 
@@ -83,7 +84,7 @@ class MyOtherClass
83
84
  def greet
84
85
  pretty_output(:welcome)
85
86
  # Or simply
86
- pou(:welcome)
87
+ pou :welcome
87
88
  end
88
89
  end
89
90
  ```
@@ -153,9 +154,9 @@ class MyClass
153
154
  end
154
155
  ```
155
156
 
156
- ### Further Customization
157
+ ## Further Customization
157
158
 
158
- #### Specifying File Name and Directory
159
+ ### Specifying File Name and Directory
159
160
 
160
161
  By default `messages_dictionary` will search for a *.yml* file named after your class (converted to snake case,
161
162
  so for the `MyClass` the file should be named *my_class.yml*)
@@ -167,13 +168,29 @@ inside the same directory. However, this behavior can be easily changed with the
167
168
  ```ruby
168
169
  class MyClass
169
170
  include MessagesDictionary
170
- has_messages_dictionary file: 'some_file.yml', dir: 'C:\my_docs'
171
+ has_messages_dictionary file: 'some_file.yml', dir: 'my_docs'
171
172
  end
172
173
  ```
173
174
 
174
175
  Both of these options are not mandatory.
175
176
 
176
- #### Specifying Messages Hash
177
+ ### Providing a custom file loader
178
+
179
+ By default the gem a messages file in YAML format. However, you might want to use a different format: for example, JSON. In this case you'll have to provide a custom loader:
180
+
181
+ ```ruby
182
+ class MyClass
183
+ include MessagesDictionary
184
+ has_messages_dictionary file: 'test_file.json', dir: 'my_dir',
185
+ file_loader: ->(file_path) { JSON.parse(File.read(file_path)) }
186
+ end
187
+ ```
188
+
189
+ The `:file_loader` option accepts a proc or a lambda that receives a path to your messages file as an argument. This lambda must return a hash object with keys and the corresponding values.
190
+
191
+ The default value for the `:file_loader` is `->(f) { YAML.load_file(f) }`.
192
+
193
+ ### Specifying Messages Hash
177
194
 
178
195
  Instead of loading messages from a file, you can pass hash to the `has_messages_dictionary` using `:messages` option:
179
196
 
@@ -186,7 +203,7 @@ end
186
203
 
187
204
  Nesting and all other features are supported as well.
188
205
 
189
- #### Specifying Output and Display Method
206
+ ### Specifying Output and Display Method
190
207
 
191
208
  By default all messages will be outputted to `STDOUT` using `puts` method, however this can be changed:
192
209
 
@@ -201,7 +218,32 @@ class MyClass
201
218
  end
202
219
  ```
203
220
 
204
- #### Providing Custom Transformation Logic
221
+ ### "Lazy" mode
222
+
223
+ By default this gem will load all messages from the given file. However, you can enable a "lazy" mode so that messages are not loaded until `pou` or `pretty_output` methods have been called. The "lazy" mode can only be enabled when the `:file` option is provided (in other words, `:lazy` has no effect with the `:messages` setting):
224
+
225
+ ```ruby
226
+ class MyClass
227
+ include MessagesDictionary
228
+ has_messages_dictionary lazy: true, file: 'my_file.yml'
229
+
230
+ def greet
231
+ pou :hi
232
+ end
233
+ end
234
+
235
+ # At this point no messages are loaded from the given file
236
+
237
+ obj = MyClass.new
238
+
239
+ # ... doing some other stuff ...
240
+
241
+ # Messages are still not loaded at this point!
242
+
243
+ obj.greet # Now all messages will be loaded from the YAML file
244
+ ```
245
+
246
+ ### Providing Custom Transformation Logic
205
247
 
206
248
  Suppose you want to transform your message somehow or even simply return it instead of printing on the screen.
207
249
  `pretty_output` method accepts an optional block for this purpose:
@@ -213,8 +255,12 @@ class MyClass
213
255
 
214
256
  def greet
215
257
  pou(:welcome) do |msg|
216
- msg.upcase!
258
+ msg.upcase
217
259
  end
260
+
261
+ # Or simply:
262
+
263
+ pou(:welcome, &:upcase)
218
264
  end
219
265
  end
220
266
 
@@ -228,7 +274,7 @@ option:
228
274
  ```ruby
229
275
  class MyClass
230
276
  include MessagesDictionary
231
- has_messages_dictionary transform: ->(msg) {msg.upcase!}
277
+ has_messages_dictionary transform: ->(msg) {msg.upcase}
232
278
 
233
279
  def greet
234
280
  pou(:welcome)
@@ -248,16 +294,54 @@ it anywhere (for example, when raising a custom error - see use case [here](http
248
294
  If you do want to output your message after transformation, you have to do it explicitly:
249
295
 
250
296
  ```ruby
297
+ def greet
298
+ pou(:welcome) do |msg|
299
+ puts msg.upcase # => Prints "WELCOME"
300
+ end
301
+ end
302
+ ```
303
+
304
+ ### Handling missing keys
305
+
306
+ By default when a non-existent key is requested, an error will be raised:
307
+
308
+ ```ruby
309
+ class MyClass
310
+ include MessagesDictionary
311
+ has_messages_dictionary messages: {key: 'value'}
312
+
251
313
  def greet
252
- pou(:welcome) do |msg|
253
- msg.upcase!
254
- puts msg # => Prints "WELCOME"
255
- end
314
+ pou :unknown_key # trying to use some unknown key...
256
315
  end
316
+ end
317
+
318
+ obj = MyClass.new
319
+
320
+ obj.greet # KeyError is raised here!
257
321
  ```
258
322
 
323
+ However, you can adjust the `:on_key_missing` option and provide a custom proc or lambda to handle all missing keys:
324
+
325
+ ```ruby
326
+ class MyClass
327
+ include MessagesDictionary
328
+ has_messages_dictionary messages: {key: 'value'},
329
+ on_key_missing: ->(key) { key } # We simply return the requested key itself
330
+
331
+ def greet
332
+ pou :unknown_key
333
+ end
334
+ end
335
+
336
+ obj = MyClass.new
337
+
338
+ obj.greet # Prints "unknown_key" to the screen, no errors will be raised
339
+ ```
340
+
341
+ So, in the example above we simply return the key itself if it was not found in the messages hash.
342
+
259
343
  ## License
260
344
 
261
345
  Licensed under the [MIT License](https://github.com/bodrovis-learning/messages_dictionary/blob/master/LICENSE).
262
346
 
263
- Copyright (c) 2016 [Ilya Bodrov](http://bodrovis.tech)
347
+ Copyright (c) 2022 [Ilya Krukowski](http://bodrovis.tech)
data/Rakefile CHANGED
@@ -1,6 +1,43 @@
1
- require 'bundler/gem_tasks'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake'
4
+ require 'rake/clean'
2
5
  require 'rspec/core/rake_task'
6
+ require 'rubocop/rake_task'
7
+
8
+ begin
9
+ require 'bundler/setup'
10
+ Bundler::GemHelper.install_tasks
11
+ rescue LoadError
12
+ puts 'although not required, bundler is recommened for running the tests'
13
+ end
3
14
 
4
15
  RSpec::Core::RakeTask.new(:spec)
5
16
 
6
- task default: :spec
17
+ RuboCop::RakeTask.new do |task|
18
+ task.requires << 'rubocop-performance'
19
+ task.requires << 'rubocop-rspec'
20
+ end
21
+
22
+ CLOBBER.include(FileList['./*.gem'])
23
+
24
+ namespace :messages_dictionary do
25
+ desc 'Updates RubyGems, installs dependencies'
26
+ task :install do
27
+ puts 'Running bundle install'
28
+ sh 'gem update --system'
29
+ sh 'bundle'
30
+ end
31
+
32
+ desc 'Builds the gem'
33
+ task :build do
34
+ puts 'Building'
35
+ sh 'gem build messages_dictionary.gemspec'
36
+ end
37
+ end
38
+
39
+ task rubospec: %w[rubocop spec]
40
+
41
+ task full_build: %w[clobber messages_dictionary:install messages_dictionary:build]
42
+
43
+ task default: :full_build