diggable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +5 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +86 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/Rakefile +16 -0
- data/lib/diggable/version.rb +6 -0
- data/lib/diggable.rb +52 -0
- data/sig/diggable.rbs +6 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51ea3367b0ba91b98b07a66b45ef0eaf147e9d377e60411f7b8f88dd92adde2d
|
4
|
+
data.tar.gz: 35ba9d00184f1ac3c3603f5f142f7948d6520385d0e7967f2824fee4753494ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1bced53ed541fc6d8a0812cb1743c817745ccb0695fc22a106ed8b437f796e98fafab24523246023d1211fbea23da7afa7f4823dd45d228ea04bb51f43b040d
|
7
|
+
data.tar.gz: 7b8dc2f5ee2c34cd0502ba8507e89ac8b23a7e1a25345c2b92f7a3c08a3718abddc2c04c36c8fe1df85e9d3cb6d44017a03d2f8db980f96360bb6e6c3f2cda84
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in diggable.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'minitest', '~> 5.0' # test framework
|
9
|
+
gem 'rake', '~> 13.0' # automation tasks
|
10
|
+
gem 'rubocop-espago', '~> 1.0' # ruby linter
|
11
|
+
gem 'shoulda-context', '~> 2.0' # more pleasant test syntax
|
12
|
+
gem 'solargraph', '~> 0.48' # language server
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
diggable (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
backport (1.2.0)
|
11
|
+
benchmark (0.2.1)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
e2mmap (0.1.0)
|
14
|
+
jaro_winkler (1.5.4)
|
15
|
+
json (2.6.3)
|
16
|
+
kramdown (2.4.0)
|
17
|
+
rexml
|
18
|
+
kramdown-parser-gfm (1.1.0)
|
19
|
+
kramdown (~> 2.0)
|
20
|
+
minitest (5.17.0)
|
21
|
+
nokogiri (1.14.2-arm64-darwin)
|
22
|
+
racc (~> 1.4)
|
23
|
+
nokogiri (1.14.2-x86_64-linux)
|
24
|
+
racc (~> 1.4)
|
25
|
+
parallel (1.22.1)
|
26
|
+
parser (3.2.1.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
racc (1.6.2)
|
29
|
+
rainbow (3.1.1)
|
30
|
+
rake (13.0.6)
|
31
|
+
regexp_parser (2.7.0)
|
32
|
+
reverse_markdown (2.1.1)
|
33
|
+
nokogiri
|
34
|
+
rexml (3.2.5)
|
35
|
+
rubocop (1.45.1)
|
36
|
+
json (~> 2.3)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.2.0.0)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml (>= 3.2.5, < 4.0)
|
42
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.26.0)
|
46
|
+
parser (>= 3.2.1.0)
|
47
|
+
rubocop-espago (1.0.2)
|
48
|
+
rubocop
|
49
|
+
ruby-progressbar (1.11.0)
|
50
|
+
shoulda-context (2.0.0)
|
51
|
+
solargraph (0.48.0)
|
52
|
+
backport (~> 1.2)
|
53
|
+
benchmark
|
54
|
+
bundler (>= 1.17.2)
|
55
|
+
diff-lcs (~> 1.4)
|
56
|
+
e2mmap
|
57
|
+
jaro_winkler (~> 1.5)
|
58
|
+
kramdown (~> 2.3)
|
59
|
+
kramdown-parser-gfm (~> 1.1)
|
60
|
+
parser (~> 3.0)
|
61
|
+
reverse_markdown (>= 1.0.5, < 3)
|
62
|
+
rubocop (>= 0.52)
|
63
|
+
thor (~> 1.0)
|
64
|
+
tilt (~> 2.0)
|
65
|
+
yard (~> 0.9, >= 0.9.24)
|
66
|
+
thor (1.2.1)
|
67
|
+
tilt (2.1.0)
|
68
|
+
unicode-display_width (2.4.2)
|
69
|
+
webrick (1.7.0)
|
70
|
+
yard (0.9.28)
|
71
|
+
webrick (~> 1.7.0)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
arm64-darwin-20
|
75
|
+
x86_64-linux
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
diggable!
|
79
|
+
minitest (~> 5.0)
|
80
|
+
rake (~> 13.0)
|
81
|
+
rubocop-espago (~> 1.0)
|
82
|
+
shoulda-context (~> 2.0)
|
83
|
+
solargraph (~> 0.48)
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.4.7
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Mateusz Drewniak
|
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,56 @@
|
|
1
|
+
# Diggable
|
2
|
+
|
3
|
+
This Ruby gem which adds a module which when included to a class enables it to be used with the `dig` method.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add diggable
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install diggable
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Include it in a class to make it *diggable*.
|
18
|
+
The `Diggable` module implements the `dig` method
|
19
|
+
so that it calls public methods.
|
20
|
+
|
21
|
+
Here's a simple example.
|
22
|
+
|
23
|
+
```rb
|
24
|
+
class MyClass
|
25
|
+
include Diggable
|
26
|
+
|
27
|
+
attr_accessor :foo, :bar
|
28
|
+
|
29
|
+
def initialize(foo:, bar:)
|
30
|
+
@foo = foo
|
31
|
+
@bar = bar
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
obj = MyClass.new foo: [1, 2 ,3], bar: { some: { inner: :value } }
|
36
|
+
obj.dig(:foo, 0) #=> 1
|
37
|
+
obj.dig(:bar, :some, :inner) #=> :value
|
38
|
+
|
39
|
+
hash = { my_obj: MyClass.new(foo: 1, bar: ['hi mom', 'hi dad']) }
|
40
|
+
hash.dig(:my_obj, :foo) #=> 1
|
41
|
+
hash.dig(:my_obj, :bar, 1) #=> 'hi dad'
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Verseth/ruby-diggable.
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
::Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = ::FileList['test/**/*_test.rb']
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubocop/rake_task'
|
13
|
+
|
14
|
+
::RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
data/lib/diggable.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'diggable/version'
|
4
|
+
|
5
|
+
# Include in a class to give it the `#dig` method.
|
6
|
+
# It's implemented so that it calls public methods.
|
7
|
+
#
|
8
|
+
# Example:
|
9
|
+
#
|
10
|
+
# class MyClass
|
11
|
+
# include Diggable
|
12
|
+
#
|
13
|
+
# attr_accessor :foo, :bar
|
14
|
+
#
|
15
|
+
# def initialize(foo:, bar:)
|
16
|
+
# @foo = foo
|
17
|
+
# @bar = bar
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# obj = MyClass.new foo: [1, 2 ,3], bar: { some: { inner: :value } }
|
22
|
+
# obj.dig(:foo, 0) #=> 1
|
23
|
+
# obj.dig(:bar, :some, :inner) #=> :value
|
24
|
+
#
|
25
|
+
# hash = { my_obj: MyClass.new(foo: 1, bar: ['hi mom', 'hi dad']) }
|
26
|
+
# hash.dig(:my_obj, :foo) #=> 1
|
27
|
+
# hash.dig(:my_obj, :bar, 1) #=> 'hi dad'
|
28
|
+
#
|
29
|
+
module Diggable
|
30
|
+
# Extracts the nested value specified by the sequence of key objects by calling `dig` at each step,
|
31
|
+
# returning `nil` if any intermediate step is `nil`.
|
32
|
+
#
|
33
|
+
# This implementation of `dig` uses `public_send` under the hood.
|
34
|
+
#
|
35
|
+
# @param args [Array<Symbol>, Array<String>]
|
36
|
+
# @raise [TypeError] value has no #dig method
|
37
|
+
# @return [Object]
|
38
|
+
def dig(*args)
|
39
|
+
return unless args.size.positive?
|
40
|
+
|
41
|
+
return unless respond_to?(key = args.shift)
|
42
|
+
|
43
|
+
value = public_send(key)
|
44
|
+
return if value.nil?
|
45
|
+
return value if args.empty?
|
46
|
+
raise ::TypeError, "#{value.class} does not have #dig method" unless value.respond_to?(:dig)
|
47
|
+
|
48
|
+
value.dig(*args)
|
49
|
+
rescue ::ArgumentError
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
data/sig/diggable.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diggable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mateusz Drewniak
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby gem which adds a module which when included to a class enables
|
14
|
+
it to be used with the `dig` method.
|
15
|
+
email:
|
16
|
+
- matmg24@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- ".ruby-version"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- lib/diggable.rb
|
30
|
+
- lib/diggable/version.rb
|
31
|
+
- sig/diggable.rbs
|
32
|
+
homepage: https://github.com/Verseth/ruby-diggable
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://github.com/Verseth/ruby-diggable
|
37
|
+
source_code_uri: https://github.com/Verseth/ruby-diggable
|
38
|
+
rubygems_mfa_required: 'true'
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.7.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.4.7
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: A Ruby gem which adds a module which when included to a class enables it
|
58
|
+
to be used with the `dig` method.
|
59
|
+
test_files: []
|