inline_transforms 0.2.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69650094317116d52d29eaaebdc3237dcf2c014d6447b2ad52631a4eabb11837
4
- data.tar.gz: 2729df1b7e99479a4101a9c53782b32a4d736e1756008f0da8fa976722799bd2
3
+ metadata.gz: 4334af4981af33dcc4fb7ead38766fddf4d25fe1d86f2db067a5ff944b4e9556
4
+ data.tar.gz: 6ac97539f4c3a359d9ae9f8b174af4831363818eb7cacd1ab7513b11470a06fb
5
5
  SHA512:
6
- metadata.gz: e1432ee3d677412d5aa6bcd9b014f2b7e5c093b7e495b760335dac315d312825890e1e26759a977639a7c69fdce09f6e9309b8b57f3bb2bcb4d06291ac1ee62c
7
- data.tar.gz: 462d39e0cf06278f6bf757ceec642496b22a7b2d06f9e8bf6d66c0fc0d4993e4c493eaea2cad25258e9c1f72549f7eb25e7925dd04b3af7a0d918a1f47d4c914
6
+ metadata.gz: bfab67d890ef4e3a0e8e2e342dc87463f7b595333b34cb521e7980b03236eb35de2b5b9db07dc8bbb20300e2798c41683cbd4fe7d33749bdf8491548f9d32963
7
+ data.tar.gz: 90efac60c1b9efaac6f335bfd6f36c8e7d607c1f868612b20fabff840dac765e9d983b4f240dd252a9cf7782553875627552bd8942aa518c28586bbc634a97c1
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## v0.3.1 (2026-09-29)
4
+ - **Chores**:
5
+ - Corrected Gemspec *changelog* URI.
6
+ - Exclude unnecessary files to reduce gem size.
7
+
8
+ ## v0.3.0 (2026-08-26)
9
+ - **Features**:
10
+ - Pass the original value to fallback/transform `Proc`s.
11
+
12
+ ## v0.2.0 (2026-08-25)
13
+ - **Features**:
14
+ - Added an `only_if` transform.
15
+
16
+ ## v0.1.0 (2026-08-25)
17
+ - **Features**:
18
+ - Initial "inline transforms" implementation.
19
+ - **Testing**:
20
+ - Proper testing of all expected behaviors.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inline_transforms.gemspec
4
+ gemspec
5
+
6
+ gem 'irb'
7
+ gem 'rake', '~> 13'
8
+ gem 'rspec', '~> 3'
9
+ gem 'rubocop'
10
+ gem 'yard'
data/Gemfile.lock ADDED
@@ -0,0 +1,129 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ inline_transforms (0.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.3)
10
+ diff-lcs (1.6.2)
11
+ erb (6.0.7)
12
+ io-console (0.9.2)
13
+ irb (1.18.0)
14
+ pp (>= 0.6.0)
15
+ prism (>= 1.3.0)
16
+ rdoc (>= 4.0.0)
17
+ reline (>= 0.4.2)
18
+ json (2.21.2)
19
+ language_server-protocol (3.17.0.6)
20
+ lint_roller (1.1.0)
21
+ logger (1.7.0)
22
+ parallel (2.1.0)
23
+ parser (3.3.12.0)
24
+ ast (~> 2.4.1)
25
+ racc
26
+ pp (0.6.4)
27
+ prettyprint
28
+ prettyprint (0.2.0)
29
+ prism (1.9.0)
30
+ racc (1.8.1)
31
+ rainbow (3.1.1)
32
+ rake (13.4.2)
33
+ rbs (4.1.3)
34
+ logger
35
+ prism (>= 1.6.0)
36
+ tsort
37
+ rdoc (8.0.0)
38
+ erb
39
+ prism (>= 1.6.0)
40
+ rbs (>= 4.0.0)
41
+ tsort
42
+ regexp_parser (2.12.0)
43
+ reline (0.7.0)
44
+ io-console (~> 0.5)
45
+ rspec (3.13.2)
46
+ rspec-core (~> 3.13.0)
47
+ rspec-expectations (~> 3.13.0)
48
+ rspec-mocks (~> 3.13.0)
49
+ rspec-core (3.13.6)
50
+ rspec-support (~> 3.13.0)
51
+ rspec-expectations (3.13.5)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.13.0)
54
+ rspec-mocks (3.13.8)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.13.0)
57
+ rspec-support (3.13.7)
58
+ rubocop (1.89.0)
59
+ json (~> 2.3)
60
+ language_server-protocol (~> 3.17.0.2)
61
+ lint_roller (~> 1.1.0)
62
+ parallel (>= 1.10)
63
+ parser (>= 3.3.0.2)
64
+ rainbow (>= 2.2.2, < 4.0)
65
+ regexp_parser (>= 2.9.3, < 3.0)
66
+ rubocop-ast (>= 1.49.0, < 2.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (>= 2.4.0, < 4.0)
69
+ rubocop-ast (1.50.0)
70
+ parser (>= 3.3.7.2)
71
+ prism (~> 1.7)
72
+ ruby-progressbar (1.13.0)
73
+ tsort (0.2.0)
74
+ unicode-display_width (3.2.0)
75
+ unicode-emoji (~> 4.1)
76
+ unicode-emoji (4.2.0)
77
+ yard (0.9.45)
78
+
79
+ PLATFORMS
80
+ ruby
81
+ x86_64-linux
82
+
83
+ DEPENDENCIES
84
+ inline_transforms!
85
+ irb
86
+ rake (~> 13)
87
+ rspec (~> 3)
88
+ rubocop
89
+ yard
90
+
91
+ CHECKSUMS
92
+ ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
93
+ bundler (4.0.14) sha256=d09a0a965cf772266a7e49e83610be7c2f4e49e61134c42a56804bb383cc24b8
94
+ diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
95
+ erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92
96
+ inline_transforms (0.3.0)
97
+ io-console (0.9.2) sha256=efa74f891dd03c0939a931dfc6e74c2813d904763d456ea9762b0525e748db08
98
+ irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3
99
+ json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
100
+ language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
101
+ lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
102
+ logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
103
+ parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356
104
+ parser (3.3.12.0) sha256=21a6d7f755d5a24dfbdc6e6b772e4e879a52e7631a88bc5a3a134606052c9828
105
+ pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570
106
+ prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
107
+ prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
108
+ racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
109
+ rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
110
+ rake (13.4.2) sha256=cb825b2bd5f1f8e91ca37bddb4b9aaf345551b4731da62949be002fa89283701
111
+ rbs (4.1.3) sha256=0c4474a9751cdc14364bfad0b3e53678323bbdc2c31683b0445932867dbab8c4
112
+ rdoc (8.0.0) sha256=03bf8c08a9639658855a0cfd77c0abca8325c227693f7f33f82957811348c469
113
+ regexp_parser (2.12.0) sha256=35a916a1d63190ab5c9009457136ae5f3c0c7512d60291d0d1378ba18ce08ebb
114
+ reline (0.7.0) sha256=5b012d8e55dbf9d450f12bde2cf7d15ff546ae80b3f8f3b30e570d431815583d
115
+ rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
116
+ rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
117
+ rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
118
+ rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
119
+ rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
120
+ rubocop (1.89.0) sha256=4dee8e3ee9c45e474834efd9e8d6fd031e8331c8dacdff0de4ad65ae0a6faae7
121
+ rubocop-ast (1.50.0) sha256=b9ca88300da0803ee222ad20cdb30494c0a784eed06fdc35d254b06d662788db
122
+ ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
123
+ tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
124
+ unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
125
+ unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
126
+ yard (0.9.45) sha256=52e211493f7cb8a3ebf7e104a25a1e73937a3103092545d34cb88fafebb3dc51
127
+
128
+ BUNDLED WITH
129
+ 4.0.14
data/README.md CHANGED
@@ -91,6 +91,9 @@ final_value = original_value.transform true => 'success',
91
91
  `only_if` lets you specify a "good" value and an `else` replacement.
92
92
 
93
93
  - If your `else` replacement is a `Proc`, it is resolved (via `call`) before being returned.
94
+ - If it has arity 0, it is `call`ed with no params.
95
+ - If it has arity 1, it is `call`ed with the original value.
96
+ - If it has arity -1 (a `lambda` with optional param), it is `call`ed with the original value.
94
97
  - This method uses **case comparison** (`===`), so you can check for range inclusion or class.
95
98
 
96
99
  ```ruby
@@ -105,6 +108,9 @@ final = value.only_if good_value, else: -> { some_method_call with_params }
105
108
  `unless` lets you specify a "bad" value and a `then` replacement.
106
109
 
107
110
  - If your `then` replacement is a `Proc`, it is resolved (via `call`) before being returned.
111
+ - If it has arity 0, it is `call`ed with no params.
112
+ - If it has arity 1, it is `call`ed with the original value.
113
+ - If it has arity -1 (a `lambda` with optional param), it is `call`ed with the original value.
108
114
  - This method uses **case comparison** (`===`), so you can check for range inclusion or class.
109
115
 
110
116
  ```ruby
@@ -119,6 +125,9 @@ final = value.unless bad_value, then: -> { some_method_call with_params }
119
125
  `transform` lets you specify a transformation hash and will return the value for the first matching key, or (if no matching key is found) the `:else` value.
120
126
 
121
127
  - Any `Proc` values in the transform hash are resolved (via `call`) before being returned.
128
+ - Values with arity 0 are `call`ed with no params.
129
+ - Values with arity 1 are `call`ed with the original value.
130
+ - Values with arity -1 (`lambda`s with an optional param) are `call`ed with the original value.
122
131
  - This method uses **case comparison** (`===`), so range and class keys work as you expect.
123
132
 
124
133
  ```ruby
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/inline_transforms/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.required_ruby_version = '>= 3.4'
5
+
6
+ spec.name = 'inline_transforms'
7
+ spec.version = InlineTransforms::VERSION
8
+ spec.authors = ['Nestor Custodio']
9
+ spec.email = ['nestor@custodio.org']
10
+
11
+ spec.summary = 'Facilitates inline value logic.'
12
+ spec.homepage = 'https://github.com/nestor-custodio/inline_transforms'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0") & Dir['*', 'lib/**/*']
16
+ spec.executables = []
17
+ spec.require_paths = ['lib']
18
+
19
+ # ---
20
+
21
+ spec.metadata = {
22
+ # See: https://guides.rubygems.org/specification-reference/#metadata
23
+
24
+ # RubyGems.org Security
25
+ #
26
+ 'allowed_push_host' => 'https://rubygems.org',
27
+ 'rubygems_mfa_required' => 'true',
28
+
29
+ # Metadata-Provided URIs
30
+ #
31
+ 'homepage_uri' => spec.homepage,
32
+ 'changelog_uri' => "#{spec.homepage}/blob/main/CHANGELOG.md"
33
+ }
34
+ end
@@ -1,3 +1,3 @@
1
1
  module InlineTransforms
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -26,10 +26,7 @@ module InlineTransforms
26
26
  def only_if(good_value, **options)
27
27
  return self if inline_transforms_equality? good_value
28
28
 
29
- alt_value = options[:else]
30
- return alt_value.call if alt_value.is_a? Proc
31
-
32
- alt_value
29
+ inline_transforms_response_processor options[:else]
33
30
  end
34
31
 
35
32
  # Returns `self` ... unless it matches a "bad" value, in which case it returns an alternate (`then:`) value.
@@ -50,10 +47,7 @@ module InlineTransforms
50
47
  def unless(bad_value, **options)
51
48
  return self unless inline_transforms_equality? bad_value
52
49
 
53
- alt_value = options[:then]
54
- return alt_value.call if alt_value.is_a? Proc
55
-
56
- alt_value
50
+ inline_transforms_response_processor options[:then]
57
51
  end
58
52
 
59
53
  # Returns `self` ... unless it matches one of the keys in the given "transformation hash", in which case the
@@ -74,8 +68,8 @@ module InlineTransforms
74
68
  def transform(**options)
75
69
  default = options.delete :else
76
70
 
77
- options.each { |key, value| return value.unless Proc, then: -> { value.call } if inline_transforms_equality? key }
78
- default
71
+ options.each { |key, value| return inline_transforms_response_processor value if inline_transforms_equality? key }
72
+ inline_transforms_response_processor default
79
73
  end
80
74
 
81
75
  private
@@ -94,6 +88,27 @@ module InlineTransforms
94
88
  value === self
95
89
  end
96
90
 
91
+ # We want to pass fallback values through as-is **except for `Proc`s**,
92
+ # which we must resolve by passing `self` _or not_, as dictated by its arity.
93
+ #
94
+ # @param response_value [Object]
95
+ # The `then`, `else`, or matching transform value from one of the above.
96
+ #
97
+ # @return [Object]
98
+ # The given `response_value`, unless it's a `Proc`, in which case we want to resolve it first.
99
+ #
100
+ # @raise [ArgumentError]
101
+ #
102
+ def inline_transforms_response_processor(response_value)
103
+ return response_value unless response_value.is_a? Proc
104
+
105
+ case response_value.arity
106
+ when 0 then response_value.call
107
+ when 1, -1 then response_value.call self
108
+ else raise ArgumentError, 'fallback Proc must be of arity 0 or 1'
109
+ end
110
+ end
111
+
97
112
  # rubocop:enable Style/CaseEquality
98
113
  end
99
114
 
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_transforms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nestor Custodio
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
@@ -15,27 +15,13 @@ executables: []
15
15
  extensions: []
16
16
  extra_rdoc_files: []
17
17
  files:
18
- - ".ruby-version"
19
- - ".yardopts"
18
+ - CHANGELOG.md
19
+ - Gemfile
20
+ - Gemfile.lock
20
21
  - LICENSE
21
22
  - README.md
22
23
  - Rakefile
23
- - docs/InlineTransforms.html
24
- - docs/Object.html
25
- - docs/_index.html
26
- - docs/class_list.html
27
- - docs/css/common.css
28
- - docs/css/full_list.css
29
- - docs/css/style.css
30
- - docs/file.README.html
31
- - docs/file_list.html
32
- - docs/frames.html
33
- - docs/index.html
34
- - docs/js/app.js
35
- - docs/js/full_list.js
36
- - docs/js/jquery.js
37
- - docs/method_list.html
38
- - docs/top-level-namespace.html
24
+ - inline_transforms.gemspec
39
25
  - lib/inline_transforms.rb
40
26
  - lib/inline_transforms/version.rb
41
27
  homepage: https://github.com/nestor-custodio/inline_transforms
@@ -43,9 +29,9 @@ licenses:
43
29
  - MIT
44
30
  metadata:
45
31
  allowed_push_host: https://rubygems.org
46
- homepage_uri: https://github.com/nestor-custodio/inline_transforms
47
- changelog_uri: https://github.com/nestor-custodio/inline_transforms/CHANGELOG.md
48
32
  rubygems_mfa_required: 'true'
33
+ homepage_uri: https://github.com/nestor-custodio/inline_transforms
34
+ changelog_uri: https://github.com/nestor-custodio/inline_transforms/blob/main/CHANGELOG.md
49
35
  rdoc_options: []
50
36
  require_paths:
51
37
  - lib
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.4
data/.yardopts DELETED
@@ -1,4 +0,0 @@
1
- --format='html'
2
- --markup='markdown'
3
- --no-private
4
- --output-dir='./docs'