inline_transforms 0.1.0 → 0.3.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/README.md +46 -3
- data/docs/InlineTransforms.html +519 -0
- data/docs/Object.html +148 -0
- data/docs/_index.html +122 -0
- data/docs/class_list.html +54 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +206 -0
- data/docs/css/style.css +1089 -0
- data/docs/file.README.html +257 -0
- data/docs/file_list.html +59 -0
- data/docs/frames.html +22 -0
- data/docs/index.html +257 -0
- data/docs/js/app.js +801 -0
- data/docs/js/full_list.js +334 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +78 -0
- data/docs/top-level-namespace.html +114 -0
- data/lib/inline_transforms/version.rb +1 -1
- data/lib/inline_transforms.rb +47 -8
- metadata +17 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html >
|
|
3
|
+
<head>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
|
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen">
|
|
8
|
+
|
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen">
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
14
|
+
|
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<title>Method List</title>
|
|
19
|
+
<base id="base_target" target="_parent">
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="content">
|
|
23
|
+
<div class="fixed_header">
|
|
24
|
+
<h1 id="full_list_header">Method List</h1>
|
|
25
|
+
<div id="full_list_nav">
|
|
26
|
+
|
|
27
|
+
<span><a target="_self" href="class_list.html">
|
|
28
|
+
Classes
|
|
29
|
+
</a></span>
|
|
30
|
+
|
|
31
|
+
<span><a target="_self" href="method_list.html">
|
|
32
|
+
Methods
|
|
33
|
+
</a></span>
|
|
34
|
+
|
|
35
|
+
<span><a target="_self" href="file_list.html">
|
|
36
|
+
Files
|
|
37
|
+
</a></span>
|
|
38
|
+
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div id="search">
|
|
42
|
+
<label for="search-class">Search:</label>
|
|
43
|
+
<input id="search-class" type="text">
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<ul id="full_list" class="method">
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
<li class="odd ">
|
|
51
|
+
<div class="item">
|
|
52
|
+
<span class='object_link'><a href="InlineTransforms.html#only_if-instance_method" title="InlineTransforms#only_if (method)">#only_if</a></span>
|
|
53
|
+
<small>InlineTransforms</small>
|
|
54
|
+
</div>
|
|
55
|
+
</li>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
<li class="even ">
|
|
59
|
+
<div class="item">
|
|
60
|
+
<span class='object_link'><a href="InlineTransforms.html#transform-instance_method" title="InlineTransforms#transform (method)">#transform</a></span>
|
|
61
|
+
<small>InlineTransforms</small>
|
|
62
|
+
</div>
|
|
63
|
+
</li>
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
<li class="odd ">
|
|
67
|
+
<div class="item">
|
|
68
|
+
<span class='object_link'><a href="InlineTransforms.html#unless-instance_method" title="InlineTransforms#unless (method)">#unless</a></span>
|
|
69
|
+
<small>InlineTransforms</small>
|
|
70
|
+
</div>
|
|
71
|
+
</li>
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
</ul>
|
|
76
|
+
</div>
|
|
77
|
+
</body>
|
|
78
|
+
</html>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>
|
|
7
|
+
Top Level Namespace
|
|
8
|
+
|
|
9
|
+
— Documentation by YARD 0.9.45
|
|
10
|
+
|
|
11
|
+
</title>
|
|
12
|
+
|
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css">
|
|
14
|
+
|
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css">
|
|
16
|
+
|
|
17
|
+
<script type="text/javascript">
|
|
18
|
+
pathId = "";
|
|
19
|
+
relpath = '';
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
+
|
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="main_progress" aria-hidden="true"></div>
|
|
31
|
+
|
|
32
|
+
<div class="nav_wrap">
|
|
33
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
34
|
+
<div id="resizer"></div>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<div id="main" tabindex="-1">
|
|
38
|
+
<div id="header">
|
|
39
|
+
<div id="menu">
|
|
40
|
+
|
|
41
|
+
<a href="_index.html">Index</a> »
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<span class="title">Top Level Namespace</span>
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<div id="search">
|
|
49
|
+
|
|
50
|
+
<a class="full_list_link" id="class_list_link"
|
|
51
|
+
href="class_list.html">
|
|
52
|
+
|
|
53
|
+
<svg width="24" height="24">
|
|
54
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
55
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
56
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
57
|
+
</svg>
|
|
58
|
+
</a>
|
|
59
|
+
|
|
60
|
+
</div>
|
|
61
|
+
<div class="clear"></div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div id="content"><h1>Top Level Namespace
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
</h1>
|
|
69
|
+
<div class="box_info">
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<h2>Defined Under Namespace</h2>
|
|
84
|
+
<p class="children">
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="InlineTransforms.html" title="InlineTransforms (module)">InlineTransforms</a></span>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Object.html" title="Object (class)">Object</a></span>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div id="footer">
|
|
107
|
+
Generated on Wed Aug 26 23:26:19 2026 by
|
|
108
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
109
|
+
0.9.45 (ruby-3.4.8).
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
</div>
|
|
113
|
+
</body>
|
|
114
|
+
</html>
|
data/lib/inline_transforms.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require_relative 'inline_transforms/version'
|
|
2
2
|
|
|
3
|
-
# Defines `unless
|
|
3
|
+
# Defines `only_if`, `unless`, and `transform`, which we'll then want to make available in `Object` instances.
|
|
4
4
|
#
|
|
5
5
|
module InlineTransforms
|
|
6
6
|
# Our use of case equality in matching bad/target values
|
|
@@ -8,6 +8,27 @@ module InlineTransforms
|
|
|
8
8
|
#
|
|
9
9
|
# rubocop:disable Style/CaseEquality
|
|
10
10
|
|
|
11
|
+
# Returns `self` _only if_ it matches a "good" value; otherwise returns an alternate (`else:`) value.
|
|
12
|
+
#
|
|
13
|
+
# (NOTE: this takes an `else: nil` named param, but is defined as taking `(**options)` because `else` is reserved.)
|
|
14
|
+
#
|
|
15
|
+
#
|
|
16
|
+
# @param good_value [Object]
|
|
17
|
+
# The one value we consider "good", and for which we'd like `self` returned.
|
|
18
|
+
#
|
|
19
|
+
# @option else: [Object]
|
|
20
|
+
# The value we'd like back if `self` does not match the `good_value` **using case comparison**.
|
|
21
|
+
# Defaults to `nil`.
|
|
22
|
+
#
|
|
23
|
+
# @return
|
|
24
|
+
# Returns either `self` or the value given as the `else:` option.
|
|
25
|
+
#
|
|
26
|
+
def only_if(good_value, **options)
|
|
27
|
+
return self if inline_transforms_equality? good_value
|
|
28
|
+
|
|
29
|
+
inline_transforms_response_processor options[:else]
|
|
30
|
+
end
|
|
31
|
+
|
|
11
32
|
# Returns `self` ... unless it matches a "bad" value, in which case it returns an alternate (`then:`) value.
|
|
12
33
|
#
|
|
13
34
|
# (NOTE: this takes a `then: nil` named param, but is defined as taking `(**options)` because `then` is reserved.)
|
|
@@ -26,10 +47,7 @@ module InlineTransforms
|
|
|
26
47
|
def unless(bad_value, **options)
|
|
27
48
|
return self unless inline_transforms_equality? bad_value
|
|
28
49
|
|
|
29
|
-
|
|
30
|
-
return alt_value.call if alt_value.is_a? Proc
|
|
31
|
-
|
|
32
|
-
alt_value
|
|
50
|
+
inline_transforms_response_processor options[:then]
|
|
33
51
|
end
|
|
34
52
|
|
|
35
53
|
# Returns `self` ... unless it matches one of the keys in the given "transformation hash", in which case the
|
|
@@ -42,7 +60,7 @@ module InlineTransforms
|
|
|
42
60
|
# A hash of keys to case-compare against `self` so we can return the corresponding value.
|
|
43
61
|
#
|
|
44
62
|
# @option else: [Object]
|
|
45
|
-
# The fallback value to return if no matching key is found.
|
|
63
|
+
# The fallback value to return if no matching key is found. Defaults to `nil`.
|
|
46
64
|
#
|
|
47
65
|
# @return
|
|
48
66
|
# Returns either `self`, one of the transformation hash values, or the `else:` option.
|
|
@@ -50,8 +68,8 @@ module InlineTransforms
|
|
|
50
68
|
def transform(**options)
|
|
51
69
|
default = options.delete :else
|
|
52
70
|
|
|
53
|
-
options.each { |key, value| return
|
|
54
|
-
default
|
|
71
|
+
options.each { |key, value| return inline_transforms_response_processor value if inline_transforms_equality? key }
|
|
72
|
+
inline_transforms_response_processor default
|
|
55
73
|
end
|
|
56
74
|
|
|
57
75
|
private
|
|
@@ -70,6 +88,27 @@ module InlineTransforms
|
|
|
70
88
|
value === self
|
|
71
89
|
end
|
|
72
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
|
+
|
|
73
112
|
# rubocop:enable Style/CaseEquality
|
|
74
113
|
end
|
|
75
114
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: inline_transforms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nestor Custodio
|
|
@@ -20,6 +20,22 @@ files:
|
|
|
20
20
|
- LICENSE
|
|
21
21
|
- README.md
|
|
22
22
|
- 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
|
|
23
39
|
- lib/inline_transforms.rb
|
|
24
40
|
- lib/inline_transforms/version.rb
|
|
25
41
|
homepage: https://github.com/nestor-custodio/inline_transforms
|