delegate_key 1.0.0 → 1.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
2
  SHA256:
3
- metadata.gz: 0b13a172ea1a1e209de4d4e64561660ee217d2a0dcebe43db3e80f846d7a7af2
4
- data.tar.gz: 6300b0d335bd59bd3db3b27fa7efc303920dbeb1e10f564dfbbc632229326599
3
+ metadata.gz: 45a23aeb0cb6c420dc1a705de6e743de61df2e0fb5f155072bf6e5fce13887b3
4
+ data.tar.gz: a9e393b50a60cf75286b92be3f40ff35643f546fe457ca2f773b4722e8cdfadc
5
5
  SHA512:
6
- metadata.gz: 457b8cdc5a40d4d51923b5f7d3124c1cb76d1dfdfebf86fd6c5557e346bcd454a42a647a5b08a59726cbc527737a37f8773bf95cd71191c486ba8ca8420dbdfc
7
- data.tar.gz: 3dc1ce94bf89e6e94436f0bdfefe09acb5f9028641fcaea9bf7ca272084f910842edb3b8458e4338ce2af2484b36008344a6a131bec88b864d556bdf3aa624b1
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/[USERNAME]/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.
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 = ">= 2.1"
20
+ spec.required_ruby_version = ">= 3.0"
21
21
 
22
22
  spec.add_development_dependency "pry"
23
23
  spec.add_development_dependency "rspec"
@@ -1,3 +1,3 @@
1
1
  module DelegateKey
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
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: :hash)."
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 = if 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
- method_names = methods.map do |method|
21
- method_def = [
22
- "def #{method_prefix}#{method}",
23
- " #{to}.public_send(:[], #{method.inspect})",
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.0.0
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: 2019-09-23 00:00:00.000000000 Z
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: '2.1'
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.0.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: []