tash 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ab6c85df581e13d681640252f50c00910b817aaca27d74b335fb4e576d179556
4
+ data.tar.gz: 648d5676b1adb47290843bb4ad988e81ee645c9b118805ca4619785f42b91730
5
+ SHA512:
6
+ metadata.gz: 9caea4c41ed62bdd53689f115b3af4eb4f807aa77175f88f45287598bf18e3a0a44e0f51123ade2a32c52d459c8392535f72a2a2f6827d5b1f081de0494de09e
7
+ data.tar.gz: 46f8610b260a5777eaa993c63436bdf46f247b18734310ab5766d6ad00e0d9ac1fadb61a5f8f81c1eceaa27b47fd750fbd701b5a59b7c9ef3e720b21b4b56955
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # [1.0.0][] (2022-06-25)
2
+
3
+ Initial release.
4
+
5
+ Support is available for all instance methods that exist on Hash except for `transform_keys` and `transform_keys!`.
6
+
7
+ [1.0.0]: https://github.com/AaronLasseigne/tash/compare/v0.0.0...v1.0.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,45 @@
1
+ # Contributing
2
+
3
+ The goal of Tash is to provide an interface that is as close to Hash as possible.
4
+ Anything that adds additional functionality to an existing method will likely be rejected since it might conflict with future changes to Hash.
5
+ Feel free to open a [discussion][] to talk through a new feature.
6
+
7
+ The goal of Tash is to be fast.
8
+ Any changes to speed it up are welcome.
9
+ Please provide [benchmark-ips][] comparisons of before an after.
10
+ An easy way to do this is to duplicate the method with a postfix of `_fast` and run it in a script or in `bin/console`.
11
+
12
+ Example:
13
+
14
+ ``` rb
15
+ t = Tash[...]
16
+
17
+ Benchmark.ips do |x|
18
+ x.report('some_method') do
19
+ ...
20
+ end
21
+
22
+ x.report('some_method_fast') do
23
+ ...
24
+ end
25
+
26
+ x.compare!
27
+ end
28
+ ```
29
+
30
+ ## Steps
31
+
32
+ 1. [Fork][] the repo.
33
+ 2. Add a breaking test for your change.
34
+ 3. Make the tests pass.
35
+ 4. Push your fork.
36
+ 5. Submit a pull request.
37
+
38
+ ## Code Style
39
+
40
+ Running the tests using `rake` (with no args) will also check for style issues in the code.
41
+ If you have a failure you cannot figure out push the PR and ask for help.
42
+
43
+ [fork]: https://github.com/AaronLasseigne/tash/fork
44
+ [discussion]: https://github.com/AaronLasseigne/tash/discussions/categories/ideas
45
+ [benchmark-ips]: https://rubygems.org/gems/benchmark-ips
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Aaron Lasseigne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # [Tash][]
2
+
3
+ Tash is a hash that allows for transformation of its keys.
4
+ A transformation block is given to change the key.
5
+ Keys can be looked up with any value that transforms into the same key.
6
+ This means a hash can be string/symbol insensitive, case insensitive, can convert camel case JSON keys to snake case Ruby keys, or anything else based on the block you provide.
7
+
8
+ [![Version](https://img.shields.io/gem/v/tash.svg?style=flat-square)](https://rubygems.org/gems/tash)
9
+ [![Test](https://img.shields.io/github/workflow/status/AaronLasseigne/tash/Test?label=Test&style=flat-square)](https://github.com/AaronLasseigne/tash/actions?query=workflow%3ATest)
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ Add it to your Gemfile:
16
+
17
+ ``` rb
18
+ gem 'tash', '~> 1.0'
19
+ ```
20
+
21
+ Or install it manually:
22
+
23
+ ``` sh
24
+ $ gem install tash --version '~> 1.0'
25
+ ```
26
+
27
+ This project uses [Semantic Versioning][].
28
+ Check out [GitHub releases][] for a detailed list of changes.
29
+
30
+ ## Usage
31
+
32
+ Let's say that you wanted to have a hash where the keys are accessible as strings or symbols (i.e. `ActiveSupport::HashWithIndifferentAccess`).
33
+
34
+ ``` rb
35
+ t = Tash[one: 1, two: 2, &:to_s]
36
+ # => {"one"=>1, "two"=>2}
37
+
38
+ t[:one]
39
+ # => 1
40
+
41
+ t['one']
42
+ # => 1
43
+
44
+ t[:three] = 9 # oops
45
+ # => 9
46
+
47
+ t['three'] = 3
48
+ # => 3
49
+
50
+ t[:three]
51
+ # => 3
52
+
53
+ t['three']
54
+ # => 3
55
+ ```
56
+
57
+ Lets say that you recieve a series of camel case JSON keys from an API call but want to access the information with Rubys typical snake case style and symbolized.
58
+
59
+ ``` rb
60
+ json = { "firstName" => "Adam", "lastName" => "DeCobray" }
61
+
62
+ t = Tash[json] do |key|
63
+ key
64
+ .to_s
65
+ .gsub(/(?<!\A)([A-Z])/, '_\1')
66
+ .downcase
67
+ .to_sym
68
+ end
69
+
70
+ t[:first_name]
71
+ # => "Adam"
72
+
73
+ t['firstName']
74
+ # => "Adam"
75
+ ```
76
+
77
+ This also works with pattern matching:
78
+
79
+ ``` rb
80
+ t = Tash[ONE: 1, MORE: 200, &:downcase]
81
+
82
+ case t
83
+ in { One: 1, More: more }
84
+ more
85
+ else
86
+ nil
87
+ end
88
+ # => 200
89
+ ```
90
+
91
+ Tash implements `to_hash` for implicit hash conversion making it usable nearly everywhere you use a hash.
92
+
93
+ Tash has every instance method Hash has except for `transform_keys` and `transform_keys!`.
94
+
95
+ [API Documentation][]
96
+
97
+ ## Contributing
98
+
99
+ If you want to contribute to Tash, please read [our contribution guidelines][].
100
+ A [complete list of contributors][] is available on GitHub.
101
+
102
+ ## License
103
+
104
+ Tash is licensed under [the MIT License][].
105
+
106
+ [Tash]: https://github.com/AaronLasseigne/tash
107
+ [semantic versioning]: http://semver.org/spec/v2.0.0.html
108
+ [GitHub releases]: https://github.com/AaronLasseigne/tash/releases
109
+ [API Documentation]: http://rubydoc.info/github/AaronLasseigne/tash
110
+ [our contribution guidelines]: CONTRIBUTING.md
111
+ [complete list of contributors]: https://github.com/AaronLasseigne/tash/graphs/contributors
112
+ [the mit license]: LICENSE.txt
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Tash
4
+ VERSION = '1.0.0'
5
+ end