messages_dictionary 1.0.0 → 2.0.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: 270aca02bdc13e851f345d7ce783fbd8329e95f2054c3865fa5b5c1cc2b09c6c
4
+ data.tar.gz: be5c5615e7c87d7423019fcd96afdf6695ea8527b7c63777c550ca8f6c4fdde7
5
5
  SHA512:
6
- metadata.gz: 4c2cf012d57620c0f2a904743bc9b40b57a509102c0d9b2876561e42cb8f1745cf8a332eca8047b416f7ae10cf0a50d316dd229a063050a6aa27903fde60372e
7
- data.tar.gz: 6e7351eb3989b960a5238a496649dd917049dc95f973326a2cfa9635162e88aadb7083609e130c1814fd3c47864156e8fe4052e3d0a3ca18a232cf74fa672552
6
+ metadata.gz: 9661d7b64b05ee3d68042938cf05f56b4606107104122e087b39ee86c0b45db79e6ec304e89785d53c1565e7f18a200e542f3ef0cff81acf94afd1cae31aa222
7
+ data.tar.gz: e401f904c1e3efa0215a0551a33f4dced1a915f7173705232aee7f660c21f04b0f4f6853b2b280a167183d9e8c2960d6287ad0f156f7f54e967f85eba88d2781
@@ -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,25 @@
1
+ # Changelog
2
+
3
+ ## 2.0.0
4
+
5
+ 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.
6
+
7
+ Previously you could say:
8
+
9
+ ```ruby
10
+ def greet
11
+ pou(:welcome) do |msg|
12
+ puts msg.upcase!
13
+ end
14
+ end
15
+ ```
16
+
17
+ Now it's recommended to use "safe" `upcase` method:
18
+
19
+ ```ruby
20
+ def greet
21
+ pou(:welcome) do |msg|
22
+ puts msg.upcase
23
+ end
24
+ end
25
+ ```
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,83 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messages_dictionary (1.0.0)
5
- hashie (~> 3.4)
4
+ messages_dictionary (2.0.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)
41
73
  messages_dictionary!
42
- rake (~> 12.0)
74
+ rake (~> 13.0)
43
75
  rspec (~> 3.6)
76
+ rubocop (~> 1.6)
77
+ rubocop-performance (~> 1.5)
78
+ rubocop-rake (~> 0.6)
79
+ rubocop-rspec (~> 2.0)
80
+ simplecov (~> 0.16)
44
81
 
45
82
  BUNDLED WITH
46
- 1.14.6
83
+ 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
 
@@ -213,8 +216,12 @@ class MyClass
213
216
 
214
217
  def greet
215
218
  pou(:welcome) do |msg|
216
- msg.upcase!
219
+ msg.upcase
217
220
  end
221
+
222
+ # Or simply:
223
+
224
+ pou(:welcome, &:upcase)
218
225
  end
219
226
  end
220
227
 
@@ -228,7 +235,7 @@ option:
228
235
  ```ruby
229
236
  class MyClass
230
237
  include MessagesDictionary
231
- has_messages_dictionary transform: ->(msg) {msg.upcase!}
238
+ has_messages_dictionary transform: ->(msg) {msg.upcase}
232
239
 
233
240
  def greet
234
241
  pou(:welcome)
@@ -248,16 +255,15 @@ it anywhere (for example, when raising a custom error - see use case [here](http
248
255
  If you do want to output your message after transformation, you have to do it explicitly:
249
256
 
250
257
  ```ruby
251
- def greet
252
- pou(:welcome) do |msg|
253
- msg.upcase!
254
- puts msg # => Prints "WELCOME"
255
- end
258
+ def greet
259
+ pou(:welcome) do |msg|
260
+ puts msg.upcase # => Prints "WELCOME"
256
261
  end
262
+ end
257
263
  ```
258
264
 
259
265
  ## License
260
266
 
261
267
  Licensed under the [MIT License](https://github.com/bodrovis-learning/messages_dictionary/blob/master/LICENSE).
262
268
 
263
- Copyright (c) 2016 [Ilya Bodrov](http://bodrovis.tech)
269
+ 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
@@ -1,38 +1,83 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MessagesDictionary
2
- def self.included(klass)
3
- klass.class_exec do
4
- define_singleton_method :has_messages_dictionary do |opts = {}|
5
- if opts[:messages]
6
- messages = Dict.new(opts[:messages])
7
- else
8
- file = opts[:file] || "#{SpecialString.new(klass.name).snake_case}.yml"
9
- file = File.expand_path(file, opts[:dir]) if opts[:dir]
10
- begin
11
- messages = Dict.new(YAML.load_file(file))
12
- rescue Errno::ENOENT
13
- abort "File #{file} does not exist..."
14
- end
4
+ # Main module that injects all the necessary methods in the target class
5
+ module Injector
6
+ using MessagesDictionary::Utils::StringUtils
7
+
8
+ def self.included(klass)
9
+ klass.extend ClassMethods
10
+ klass.include InstanceMethods
11
+ end
12
+
13
+ # Class methods to be defined in the target (where the module was included)
14
+ module ClassMethods
15
+ # rubocop:disable Naming/PredicateName
16
+ # This is the main method that equips the target class
17
+ # with all the necesary goodies
18
+ def has_messages_dictionary(opts = {})
19
+ # rubocop:enable Naming/PredicateName
20
+ messages = MessagesDictionary::Utils::Dict.new(
21
+ opts.fetch(:messages) { __from_file(opts) }
22
+ )
23
+
24
+ const_set(:DICTIONARY_CONF, {msgs: messages,
25
+ output: opts[:output] || $stdout,
26
+ method: opts[:method] || :puts,
27
+ transform: opts[:transform]})
28
+ end
29
+
30
+ private
31
+
32
+ def __from_file(opts)
33
+ file = opts[:file] || "#{name.nil? ? 'unknown' : name.snakecase}.yml"
34
+ file = File.expand_path(file, opts[:dir]) if opts[:dir]
35
+
36
+ begin
37
+ YAML.load_file(file)
38
+ rescue Errno::ENOENT
39
+ abort "File #{file} does not exist..."
15
40
  end
16
- klass.const_set(:DICTIONARY_CONF, {msgs: messages.extend(Hashie::Extensions::DeepFetch),
17
- output: opts[:output] || STDOUT,
18
- method: opts[:method] || :puts,
19
- transform: opts[:transform]})
20
41
  end
42
+ end
21
43
 
22
- define_method :pretty_output do |key, values = {}, &block|
23
- msg = klass::DICTIONARY_CONF[:msgs].deep_fetch(*key.to_s.split('.')) do
44
+ # Instance methods to be defined in the target class
45
+ module InstanceMethods
46
+ # This method will output your messages, perform interpolation,
47
+ # and transformations
48
+ def pretty_output(key, values = {}, &block)
49
+ msg = self.class::DICTIONARY_CONF[:msgs].deep_fetch(*key.to_s.split('.')) do
24
50
  raise KeyError, "#{key} cannot be found in the provided file..."
25
51
  end
52
+
53
+ __process(
54
+ __replace(msg, values),
55
+ &block
56
+ )
57
+ end
58
+
59
+ private :pretty_output
60
+ alias pou pretty_output
61
+
62
+ private
63
+
64
+ def __replace(msg, values)
26
65
  values.each do |k, v|
27
- msg.gsub!(Regexp.new('\{\{' + k.to_s + '\}\}'), v.to_s)
66
+ msg.gsub!(Regexp.new("\\{\\{#{k}\\}\\}"), v.to_s)
67
+ end
68
+
69
+ msg
70
+ end
71
+
72
+ def __process(msg, &block)
73
+ transform = block || self.class::DICTIONARY_CONF[:transform]
74
+
75
+ if transform
76
+ transform.call(msg)
77
+ else
78
+ self.class::DICTIONARY_CONF[:output].send(self.class::DICTIONARY_CONF[:method].to_sym, msg)
28
79
  end
29
- transform = block || klass::DICTIONARY_CONF[:transform]
30
- transform ?
31
- transform.call(msg) :
32
- klass::DICTIONARY_CONF[:output].send(klass::DICTIONARY_CONF[:method].to_sym, msg)
33
80
  end
34
- private :pretty_output
35
- alias_method :pou, :pretty_output
36
81
  end
37
82
  end
38
- end
83
+ end
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MessagesDictionary
2
- class Dict < Hash
3
- include Hashie::Extensions::MergeInitializer
4
- include Hashie::Extensions::IndifferentAccess
4
+ module Utils
5
+ class Dict < Hash
6
+ include Hashie::Extensions::MergeInitializer
7
+ include Hashie::Extensions::IndifferentAccess
8
+ include Hashie::Extensions::DeepFetch
9
+ end
5
10
  end
6
- end
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MessagesDictionary
4
+ module Utils
5
+ # Utility methods for strings
6
+ module StringUtils
7
+ refine String do
8
+ # Underscore a string such that camelcase, dashes and spaces are
9
+ # replaced by underscores.
10
+ def snakecase
11
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
12
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
13
+ tr('-', '_').
14
+ gsub(/\s/, '_').
15
+ gsub(/__+/, '_').
16
+ downcase
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MessagesDictionary
2
- VERSION = '1.0.0'
3
- end
4
+ VERSION = '2.0.0'
5
+ end