delegate_key 1.0.0 → 1.1.0
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 +4 -4
- data/.github/workflows/tests.yml +25 -0
- data/README.md +1 -7
- data/delegate_key.gemspec +1 -1
- data/lib/delegate_key/version.rb +1 -1
- data/lib/delegate_key.rb +8 -13
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a23aeb0cb6c420dc1a705de6e743de61df2e0fb5f155072bf6e5fce13887b3
|
4
|
+
data.tar.gz: a9e393b50a60cf75286b92be3f40ff35643f546fe457ca2f773b4722e8cdfadc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 158d7765bae8da9567409785ed97bb1d4d26efdeac0fdf9c66d2f7a7789e77e137d79a9d1338a95df4617a2398a4b1f6a67a728cbb0d8acbd4244ab875e168aa
|
7
|
+
data.tar.gz: f8a3952d862440bf52d5995b02d3fca3c22a35ab4ef750f423a49c07eb9d352cc768725e511b7f1b469fb690596188811085bc203213a5b1e87d1b3265ef33f5
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: ["master"]
|
6
|
+
pull_request:
|
7
|
+
branches: ["master"]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby-version: ["3.0", "3.1", "3.2"]
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v3
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true
|
25
|
+
- run: bundle exec rspec spec
|
data/README.md
CHANGED
@@ -124,15 +124,9 @@ end
|
|
124
124
|
Foo.new.key # => NoMethodError: private method `key' called for #<Foo:0x00007fc24531dd28>
|
125
125
|
```
|
126
126
|
|
127
|
-
## Development
|
128
|
-
|
129
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
130
|
-
|
131
|
-
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
132
|
-
|
133
127
|
## Contributing
|
134
128
|
|
135
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
129
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ilyasgaraev/delegate_key. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
136
130
|
|
137
131
|
## License
|
138
132
|
|
data/delegate_key.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^spec/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = ">=
|
20
|
+
spec.required_ruby_version = ">= 3.0"
|
21
21
|
|
22
22
|
spec.add_development_dependency "pry"
|
23
23
|
spec.add_development_dependency "rspec"
|
data/lib/delegate_key/version.rb
CHANGED
data/lib/delegate_key.rb
CHANGED
@@ -1,32 +1,27 @@
|
|
1
1
|
class Module
|
2
2
|
def delegate_key(*methods, to: nil, prefix: nil, private: nil)
|
3
3
|
unless to
|
4
|
-
raise ArgumentError, "Delegation needs a target. Supply a keyword argument 'to' (e.g. delegate_key :key, to: :
|
4
|
+
raise ArgumentError, "Delegation needs a target. Supply a keyword argument 'to' (e.g. delegate_key :key, to: :some_hash)."
|
5
5
|
end
|
6
6
|
|
7
7
|
if prefix == true && /^[^a-z_]/.match?(to)
|
8
8
|
raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
|
9
9
|
end
|
10
10
|
|
11
|
-
method_prefix =
|
12
|
-
"#{prefix == true ? to : prefix}_"
|
13
|
-
else
|
14
|
-
""
|
15
|
-
end
|
11
|
+
method_prefix = prefix ? "#{prefix == true ? to : prefix}_" : ""
|
16
12
|
|
17
13
|
location = caller_locations(1, 1).first
|
18
14
|
file, line = location.path, location.lineno
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"
|
16
|
+
method_def = []
|
17
|
+
method_names = methods.each do |method|
|
18
|
+
method_def <<
|
19
|
+
"def #{method_prefix}#{method}" <<
|
20
|
+
" #{to}.public_send(:[], #{method.inspect})" <<
|
24
21
|
"end"
|
25
|
-
].join ";"
|
26
|
-
|
27
|
-
module_eval(method_def, file, line)
|
28
22
|
end
|
29
23
|
|
24
|
+
module_eval(method_def.join(";"), file, line)
|
30
25
|
private(*method_names) if private
|
31
26
|
method_names
|
32
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delegate_key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilyas Garaev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -46,6 +46,7 @@ executables: []
|
|
46
46
|
extensions: []
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
|
+
- ".github/workflows/tests.yml"
|
49
50
|
- ".gitignore"
|
50
51
|
- ".rspec"
|
51
52
|
- CODE_OF_CONDUCT.md
|
@@ -63,7 +64,7 @@ homepage: https://github.com/ilyasgaraev/delegate_key
|
|
63
64
|
licenses:
|
64
65
|
- MIT
|
65
66
|
metadata: {}
|
66
|
-
post_install_message:
|
67
|
+
post_install_message:
|
67
68
|
rdoc_options: []
|
68
69
|
require_paths:
|
69
70
|
- lib
|
@@ -71,15 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
72
|
requirements:
|
72
73
|
- - ">="
|
73
74
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
75
|
+
version: '3.0'
|
75
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
77
|
requirements:
|
77
78
|
- - ">="
|
78
79
|
- !ruby/object:Gem::Version
|
79
80
|
version: '0'
|
80
81
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
82
|
+
rubygems_version: 3.4.10
|
83
|
+
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Provides a delegate_key class method
|
85
86
|
test_files: []
|