contextualizer 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +5 -4
- data/contextualizer.gemspec +4 -5
- data/lib/contextualizer/callable.rb +5 -4
- data/lib/contextualizer/version.rb +3 -1
- data/lib/contextualizer.rb +13 -11
- metadata +8 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1424baf84e6af815afc2c61de2e1c2cf74c5ee96afbbfb123fccb169a0076a19
|
4
|
+
data.tar.gz: 6a69f1ddd869d3bc0ccdadff2bf8d57b2f312dd510947631bcb126a9b3a33060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e3572d4f21a19cc7240e5db085bf6f5cf500fdc81622b8f66a241d203006a57355f0912ceedece41491aef714bb4c4c6ce735c8eae8153225a1ec0eea9fb92
|
7
|
+
data.tar.gz: 3581f6d903d188a9ee89bf3dc75e3b1ecb07a5b612735782e0fd704e35607cab730eb4a34366e3a67b3fe351cd99ed3d886513abb0046901ef2efbd0404220e0
|
data/.github/workflows/tests.yml
CHANGED
@@ -11,18 +11,19 @@ jobs:
|
|
11
11
|
runs-on: ubuntu-latest
|
12
12
|
strategy:
|
13
13
|
matrix:
|
14
|
-
ruby-version: [
|
14
|
+
ruby-version: ['3.0', '3.1', '3.2', '3.3']
|
15
15
|
steps:
|
16
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v4
|
17
17
|
- name: Set up Ruby
|
18
18
|
uses: ruby/setup-ruby@v1
|
19
19
|
with:
|
20
20
|
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
bundler: '2.5.14'
|
21
22
|
bundler-cache: true
|
22
23
|
- name: Run tests
|
23
24
|
run: bundle exec rake
|
24
25
|
- name: Coveralls GitHub Action
|
25
|
-
if: matrix.ruby-version == '3.
|
26
|
-
uses: coverallsapp/github-action@
|
26
|
+
if: matrix.ruby-version == '3.3'
|
27
|
+
uses: coverallsapp/github-action@v2
|
27
28
|
with:
|
28
29
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/contextualizer.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
lib = File.expand_path("../lib", __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "contextualizer/version"
|
@@ -21,11 +22,9 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
23
|
spec.require_paths = ["lib"]
|
23
24
|
|
24
|
-
spec.required_ruby_version = ">=
|
25
|
-
|
26
|
-
spec.add_dependency "ruby2_keywords"
|
25
|
+
spec.required_ruby_version = ">= 3.0.0"
|
27
26
|
|
28
|
-
spec.add_development_dependency "bundler", "
|
27
|
+
spec.add_development_dependency "bundler", ">= 2.5.0"
|
29
28
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
30
29
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
30
|
spec.add_development_dependency "simplecov-lcov", '~> 0.8.0'
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "contextualizer"
|
3
4
|
|
4
5
|
module Contextualizer
|
5
6
|
module Callable
|
6
|
-
|
7
|
-
new(ctx).call(
|
7
|
+
def call(ctx,...)
|
8
|
+
new(ctx).call(...)
|
8
9
|
end
|
9
10
|
|
10
11
|
def self.extended(klass)
|
data/lib/contextualizer.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "contextualizer/version"
|
2
4
|
|
3
5
|
module Contextualizer
|
4
6
|
OPTIONAL = Object.new.freeze
|
@@ -24,14 +26,14 @@ module Contextualizer
|
|
24
26
|
def self.init_for(setter, inherited = true)
|
25
27
|
Module.new do |mod|
|
26
28
|
if inherited
|
27
|
-
mod.send(:define_method, :initialize) do |
|
28
|
-
super(
|
29
|
-
setter.set(self,
|
29
|
+
mod.send(:define_method, :initialize) do |ctx = {}|
|
30
|
+
super(ctx)
|
31
|
+
setter.set(self, ctx)
|
30
32
|
end
|
31
33
|
else
|
32
|
-
mod.send(:define_method, :initialize) do |
|
34
|
+
mod.send(:define_method, :initialize) do |ctx = {}|
|
33
35
|
super()
|
34
|
-
setter.set(self,
|
36
|
+
setter.set(self, ctx)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -50,14 +52,14 @@ module Contextualizer
|
|
50
52
|
@with_default.merge!(with_default)
|
51
53
|
end
|
52
54
|
|
53
|
-
def set(obj,
|
55
|
+
def set(obj, ctx)
|
54
56
|
context = obj.context&.dup || {}
|
55
57
|
|
56
|
-
@with_default.each { |key, default| context[key] =
|
57
|
-
@optional.each { |key| context[key] =
|
58
|
+
@with_default.each { |key, default| context[key] = ctx.fetch(key, default) }
|
59
|
+
@optional.each { |key| context[key] = ctx[key] if ctx.key?(key) }
|
58
60
|
@mandatory.each do |key|
|
59
|
-
fail ":#{key} was not found in scope" unless
|
60
|
-
context[key] =
|
61
|
+
fail ":#{key} was not found in scope" unless ctx.key?(key)
|
62
|
+
context[key] = ctx[key]
|
61
63
|
end
|
62
64
|
|
63
65
|
context.each do |attr, value|
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contextualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Herrero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: ruby2_keywords
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
|
-
- - "
|
17
|
+
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
19
|
+
version: 2.5.0
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
|
-
- - "
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.
|
26
|
+
version: 2.5.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +142,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
142
|
requirements:
|
157
143
|
- - ">="
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
145
|
+
version: 3.0.0
|
160
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
147
|
requirements:
|
162
148
|
- - ">="
|
163
149
|
- !ruby/object:Gem::Version
|
164
150
|
version: '0'
|
165
151
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
152
|
+
rubygems_version: 3.2.3
|
167
153
|
signing_key:
|
168
154
|
specification_version: 4
|
169
155
|
summary: Allows to define context values for your objects
|