distorted 0.6.0 → 0.7.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 +2 -2
- data/bin/console +14 -0
- data/bin/distorted +6 -0
- data/bin/setup +8 -0
- data/lib/distorted.rb +2 -0
- data/lib/distorted/checking_you_out.rb +116 -13
- data/lib/distorted/{types → checking_you_out}/README +0 -0
- data/lib/distorted/checking_you_out/application.yaml +33 -0
- data/lib/distorted/{types → checking_you_out}/font.yaml +0 -0
- data/lib/distorted/checking_you_out/image.yaml +108 -0
- data/lib/distorted/click_again.rb +333 -0
- data/lib/distorted/element_of_media.rb +2 -0
- data/lib/distorted/element_of_media/change.rb +119 -0
- data/lib/distorted/element_of_media/compound.rb +120 -0
- data/lib/distorted/floor.rb +17 -0
- data/lib/distorted/invoker.rb +97 -0
- data/lib/distorted/media_molecule.rb +58 -0
- data/lib/distorted/media_molecule/font.rb +195 -0
- data/lib/distorted/media_molecule/image.rb +33 -0
- data/lib/distorted/media_molecule/pdf.rb +44 -0
- data/lib/distorted/media_molecule/svg.rb +45 -0
- data/lib/distorted/media_molecule/text.rb +203 -0
- data/lib/distorted/media_molecule/video.rb +18 -0
- data/lib/distorted/modular_technology/gstreamer.rb +174 -0
- data/lib/distorted/modular_technology/vips.rb +4 -4
- data/lib/distorted/modular_technology/vips/foreign.rb +489 -0
- data/lib/distorted/modular_technology/vips/load.rb +133 -0
- data/lib/distorted/modular_technology/{vips_save.rb → vips/save.rb} +23 -34
- data/lib/distorted/monkey_business/encoding.rb +317 -0
- data/lib/distorted/monkey_business/hash.rb +0 -15
- data/lib/distorted/{modular_technology/triple_counter.rb → triple_counter.rb} +8 -1
- data/lib/distorted/version.rb +16 -16
- metadata +59 -46
- data/lib/distorted/injection_of_love.rb +0 -247
- data/lib/distorted/modular_technology/vips_load.rb +0 -77
- data/lib/distorted/molecule/C18H27NO3.rb +0 -10
- data/lib/distorted/molecule/font.rb +0 -198
- data/lib/distorted/molecule/image.rb +0 -36
- data/lib/distorted/molecule/pdf.rb +0 -119
- data/lib/distorted/molecule/svg.rb +0 -60
- data/lib/distorted/molecule/text.rb +0 -225
- data/lib/distorted/molecule/video.rb +0 -195
- data/lib/distorted/monkey_business/mnemoniq.rb +0 -8
- data/lib/distorted/types/application.yaml +0 -8
@@ -15,19 +15,4 @@ class Hash
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
# https://github.com/dam13n/ruby-bury/blob/master/hash.rb
|
19
|
-
# This is not packaged as a Gem or I'd be using it instead of including my own.
|
20
|
-
def bury(*args)
|
21
|
-
if args.count < 2
|
22
|
-
raise ArgumentError.new('2 or more arguments required')
|
23
|
-
elsif args.count == 2
|
24
|
-
self[args[0]] = args[1]
|
25
|
-
else
|
26
|
-
arg = args.shift
|
27
|
-
self[arg] = {} unless self[arg]
|
28
|
-
self[arg].bury(*args) unless args.empty?
|
29
|
-
end
|
30
|
-
self
|
31
|
-
end
|
32
|
-
|
33
18
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
TripleCounter = Struct.new(:major, :minor, :micro) do
|
2
2
|
attr_reader :major, :minor, :micro
|
3
3
|
|
4
|
-
|
4
|
+
# Include a catch-all so we can splat Array-generating functions
|
5
|
+
# into TripleCounter.new(), e.g. Ruby/GStreamer's library version:
|
6
|
+
# irb> require 'gst'
|
7
|
+
# => true
|
8
|
+
# irb> Gst.version
|
9
|
+
# => [1, 19, 0, 1]
|
10
|
+
def initialize(major = 0, minor = 0, micro = 0, *_)
|
5
11
|
@major = major
|
6
12
|
@minor = minor
|
7
13
|
@micro = micro
|
14
|
+
super(major, minor, micro) # Intentionally not passing our splat to `super`
|
8
15
|
end
|
9
16
|
|
10
17
|
def to_s
|
data/lib/distorted/version.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#
|
2
|
-
# `.........-` `:/:::://.`
|
3
|
-
# `+/``+ssss:``-/:` `:o+y. `::::-----``
|
4
|
-
# -+- :hmNNmdhs- `o++` `-:--/ -/... ./shhyoy. +mmmmds+:--...`
|
5
|
-
# .//``odmNmmd+++` :+/h:-------------:+. ./...-..........---/--:.------// -.--------//o//o+/+- :hhdmmmmmh/`-/-`
|
6
|
-
# `:+- :ymNmmyy:...-:` /: ./////////////- ::/:/- `++++++++` -y /:.`.////+- /////- `/+++++++. :- .::+sydmNm+ `/+.
|
7
|
-
# -+:` /syyyo:--:+oso` /: ---:::::::syys. -yoy+s` :mmmmmmmd- .h` ``:osshhyyy` /oshhs` -:::::::. :: `-..-/dmo` `/yo:
|
8
|
-
# `/o:--------:+syyy++``+s+++++++++/``:h+os``oshdos``odhhhddyy-`.h.`.ssyhmmdmoh/``o+mmho``:++++++++++y+``----::``-oyss.
|
9
|
-
# +sssssssyyyyyhdmmsyo-+/----------.`.yooy-`-hodss/``---------.`.h-`.sohdhsymhsy.`:+yNmy/`.-----------:++ooooooo+sss+`
|
10
|
-
# `+dmmmdddddmmNNddhsyosooooooooooooooysoysssyymssssssssssssssssshyssyoh:` .mhsyssssodddyooooooooooooooysoyyyyyyyyy/
|
11
|
-
# /mNmdddhmdmmdy+-+mdhhhhhhhhhhhhhhhmhhyhhhmdmmdhhhhhhhhhhhhhhhdhhhsm+ ydddhhhhd-hdmdddddddddddddddyhdhdmmNms.
|
12
|
-
# .---.......` -yhNmmhddhhhdhmhmhddmNNmyyy+dmNdydhyyyhddhmmmmNmhh. -hyhNNNh: .mNmdmdddhhhdddmmyssssssso:
|
13
|
-
# `/oooooooooooooo:`-+o+/. `+oo+o++++ooo+oooooo- `-+oo/` :oooooooooooooo/
|
14
|
-
#
|
1
|
+
#
|
2
|
+
# `.........-` `:/:::://.`
|
3
|
+
# `+/``+ssss:``-/:` `:o+y. `::::-----``
|
4
|
+
# -+- :hmNNmdhs- `o++` `-:--/ -/... ./shhyoy. +mmmmds+:--...`
|
5
|
+
# .//``odmNmmd+++` :+/h:-------------:+. ./...-..........---/--:.------// -.--------//o//o+/+- :hhdmmmmmh/`-/-`
|
6
|
+
# `:+- :ymNmmyy:...-:` /: ./////////////- ::/:/- `++++++++` -y /:.`.////+- /////- `/+++++++. :- .::+sydmNm+ `/+.
|
7
|
+
# -+:` /syyyo:--:+oso` /: ---:::::::syys. -yoy+s` :mmmmmmmd- .h` ``:osshhyyy` /oshhs` -:::::::. :: `-..-/dmo` `/yo:
|
8
|
+
# `/o:--------:+syyy++``+s+++++++++/``:h+os``oshdos``odhhhddyy-`.h.`.ssyhmmdmoh/``o+mmho``:++++++++++y+``----::``-oyss.
|
9
|
+
# +sssssssyyyyyhdmmsyo-+/----------.`.yooy-`-hodss/``---------.`.h-`.sohdhsymhsy.`:+yNmy/`.-----------:++ooooooo+sss+`
|
10
|
+
# `+dmmmdddddmmNNddhsyosooooooooooooooysoysssyymssssssssssssssssshyssyoh:` .mhsyssssodddyooooooooooooooysoyyyyyyyyy/
|
11
|
+
# /mNmdddhmdmmdy+-+mdhhhhhhhhhhhhhhhmhhyhhhmdmmdhhhhhhhhhhhhhhhdhhhsm+ ydddhhhhd-hdmdddddddddddddddyhdhdmmNms.
|
12
|
+
# .---.......` -yhNmmhddhhhdhmhmhddmNNmyyy+dmNdydhyyyhddhmmmmNmhh. -hyhNNNh: .mNmdmdddhhhdddmmyssssssso:
|
13
|
+
# `/oooooooooooooo:`-+o+/. `+oo+o++++ooo+oooooo- `-+oo/` :oooooooooooooo/
|
14
|
+
#
|
15
15
|
|
16
|
-
require_relative '
|
16
|
+
require_relative 'triple_counter'
|
17
17
|
|
18
18
|
module Cooltrainer
|
19
19
|
module DistorteD
|
20
|
-
VERSION = TripleCounter.new(0,
|
20
|
+
VERSION = TripleCounter.new(0, 7, 0)
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distorted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okeeblow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
47
|
+
version: '5.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: gstreamer
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.4'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.4'
|
54
|
+
version: '5.14'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: mime-types
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
61
|
+
version: '3.3'
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
68
|
+
version: '3.3'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: ruby-filemagic
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,33 +109,33 @@ dependencies:
|
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: 0.2.5
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: gstreamer
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
117
|
+
version: '3.4'
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
124
|
+
version: '3.4'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
126
|
+
name: hexapdf
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
131
|
+
version: '0.13'
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
138
|
+
version: '0.13'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: charlock_holmes
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,15 +150,33 @@ dependencies:
|
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: '0.7'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: ttfunk
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.6'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.6'
|
167
167
|
description: Ruby implementation of core file-format operations used by DistorteD-Jekyll.
|
168
168
|
email:
|
169
169
|
- root@cooltrainer.org
|
170
|
-
executables:
|
170
|
+
executables:
|
171
|
+
- distorted
|
171
172
|
extensions: []
|
172
173
|
extra_rdoc_files: []
|
173
174
|
files:
|
174
175
|
- LICENSE
|
175
176
|
- README.md
|
177
|
+
- bin/console
|
178
|
+
- bin/distorted
|
179
|
+
- bin/setup
|
176
180
|
- font/1252/LICENSE/MoreLessPerfectDOSVGA437/img/Less_Perfect_DOS_VGA.png
|
177
181
|
- font/1252/LICENSE/MoreLessPerfectDOSVGA437/img/More_Perfect_DOS_VGA.png
|
178
182
|
- font/1252/LICENSE/MoreLessPerfectDOSVGA437/img/Perfect_DOS_VGA.png
|
@@ -199,29 +203,38 @@ files:
|
|
199
203
|
- font/850/Profont/readme.txt
|
200
204
|
- font/932/LICENSE/README-ttf.txt
|
201
205
|
- font/932/mona.ttf
|
206
|
+
- lib/distorted.rb
|
202
207
|
- lib/distorted/checking_you_out.rb
|
208
|
+
- lib/distorted/checking_you_out/README
|
209
|
+
- lib/distorted/checking_you_out/application.yaml
|
210
|
+
- lib/distorted/checking_you_out/font.yaml
|
211
|
+
- lib/distorted/checking_you_out/image.yaml
|
212
|
+
- lib/distorted/click_again.rb
|
213
|
+
- lib/distorted/element_of_media.rb
|
214
|
+
- lib/distorted/element_of_media/change.rb
|
215
|
+
- lib/distorted/element_of_media/compound.rb
|
203
216
|
- lib/distorted/error_code.rb
|
204
|
-
- lib/distorted/
|
217
|
+
- lib/distorted/floor.rb
|
218
|
+
- lib/distorted/invoker.rb
|
219
|
+
- lib/distorted/media_molecule.rb
|
220
|
+
- lib/distorted/media_molecule/font.rb
|
221
|
+
- lib/distorted/media_molecule/image.rb
|
222
|
+
- lib/distorted/media_molecule/pdf.rb
|
223
|
+
- lib/distorted/media_molecule/svg.rb
|
224
|
+
- lib/distorted/media_molecule/text.rb
|
225
|
+
- lib/distorted/media_molecule/video.rb
|
226
|
+
- lib/distorted/modular_technology/gstreamer.rb
|
205
227
|
- lib/distorted/modular_technology/pango.rb
|
206
|
-
- lib/distorted/modular_technology/triple_counter.rb
|
207
228
|
- lib/distorted/modular_technology/ttfunk.rb
|
208
229
|
- lib/distorted/modular_technology/vips.rb
|
209
|
-
- lib/distorted/modular_technology/
|
210
|
-
- lib/distorted/modular_technology/
|
211
|
-
- lib/distorted/
|
212
|
-
- lib/distorted/
|
213
|
-
- lib/distorted/molecule/image.rb
|
214
|
-
- lib/distorted/molecule/pdf.rb
|
215
|
-
- lib/distorted/molecule/svg.rb
|
216
|
-
- lib/distorted/molecule/text.rb
|
217
|
-
- lib/distorted/molecule/video.rb
|
230
|
+
- lib/distorted/modular_technology/vips/foreign.rb
|
231
|
+
- lib/distorted/modular_technology/vips/load.rb
|
232
|
+
- lib/distorted/modular_technology/vips/save.rb
|
233
|
+
- lib/distorted/monkey_business/encoding.rb
|
218
234
|
- lib/distorted/monkey_business/hash.rb
|
219
|
-
- lib/distorted/monkey_business/mnemoniq.rb
|
220
235
|
- lib/distorted/monkey_business/set.rb
|
221
236
|
- lib/distorted/monkey_business/string.rb
|
222
|
-
- lib/distorted/
|
223
|
-
- lib/distorted/types/application.yaml
|
224
|
-
- lib/distorted/types/font.yaml
|
237
|
+
- lib/distorted/triple_counter.rb
|
225
238
|
- lib/distorted/version.rb
|
226
239
|
- test/distorted_test.rb
|
227
240
|
- test/test_helper.rb
|
@@ -1,247 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'distorted/monkey_business/set'
|
3
|
-
|
4
|
-
|
5
|
-
# This Module supports Module "Piles"* in DistorteD by merging
|
6
|
-
# an arbitrarily-deep nest of attribute-definition constants
|
7
|
-
# into a single combined datastructure per constant at include-/
|
8
|
-
# extend-/prepend-time.
|
9
|
-
# [*] 'Monad' doesn't feel quite right, but http://www.geekculture.com/joyoftech/joyimages/469.gif
|
10
|
-
#
|
11
|
-
# The combined structures can be accessed in one shot and trusted as
|
12
|
-
# a source of truth, versus inspecting Module::nesting or whatever
|
13
|
-
# to iterate over the masked same-Symbol constants we'd get when
|
14
|
-
# including/extending/prepending in Ruby normally:
|
15
|
-
# - https://ruby-doc.org/core/Module.html#method-c-nesting
|
16
|
-
# - http://valve.github.io/blog/2013/10/26/constant-resolution-in-ruby/
|
17
|
-
|
18
|
-
# There's some general redundancy here with Bundler's const_get_safely:
|
19
|
-
# https://ruby-doc.org/stdlib/libdoc/bundler/rdoc/Bundler/SharedHelpers.html#method-i-const_get_safely
|
20
|
-
#
|
21
|
-
# …but even though I use (and enjoy using) Bundler it feels Wrong™ to me to have
|
22
|
-
# that method in stdlib and especially in Core but not as part of Module since
|
23
|
-
# 'Bundler' still feels like a third-party namespace to me v(._. )v
|
24
|
-
|
25
|
-
|
26
|
-
module Cooltrainer; end
|
27
|
-
module Cooltrainer::DistorteD; end
|
28
|
-
module Cooltrainer::DistorteD::InjectionOfLove
|
29
|
-
|
30
|
-
# These hold (possibly-runtime-generated) Sets of MIME::Types (from our loader)*
|
31
|
-
# describing any supported input media-types (:LOWER_WORLD)
|
32
|
-
# and any supported output media-types (:OUTER_LIMITS).
|
33
|
-
TYPE_CONSTANTS = Set[
|
34
|
-
:LOWER_WORLD,
|
35
|
-
:OUTER_LIMITS,
|
36
|
-
]
|
37
|
-
# These hold Hashes or Sets describing supported attributes,
|
38
|
-
# supported attribute-values (otherwise freeform),
|
39
|
-
# attribute defaults if any, and mappings for any of those things
|
40
|
-
# to any aliased equivalents for normalization and localization.
|
41
|
-
ATTRIBUTE_CONSTANTS = Set[
|
42
|
-
:ATTRIBUTES,
|
43
|
-
:ATTRIBUTES_DEFAULT,
|
44
|
-
:ATTRIBUTES_VALUES,
|
45
|
-
]
|
46
|
-
# 🄒 All of the above.
|
47
|
-
DISTORTED_CONSTANTS = Set[].merge(TYPE_CONSTANTS).merge(ATTRIBUTE_CONSTANTS)
|
48
|
-
|
49
|
-
# Name of our fully-merged-Hash's class variable.
|
50
|
-
AFTERPARTY = :@@DistorteD
|
51
|
-
|
52
|
-
|
53
|
-
# Activate this module when it's included.
|
54
|
-
# We will merge DistorteD attributes to the singleton class from
|
55
|
-
# our including context and from out including context's included_modules,
|
56
|
-
# then we will define methods in the including context to perpetuate
|
57
|
-
# the merging process when that context is included/extended/prepended.
|
58
|
-
def self.included(otra)
|
59
|
-
self::Injection_Of_Love.call(otra)
|
60
|
-
super
|
61
|
-
end
|
62
|
-
|
63
|
-
# "Attribute" fragments are processed in one additional step to support
|
64
|
-
# aliased/equivalent attribute names and values.
|
65
|
-
# This is a quality-of-life feature to help normalize/localize attributes
|
66
|
-
# defined in a wide range of places by multiple unrelated upstream devs.
|
67
|
-
#
|
68
|
-
# For example, libvips savers expect a single-character upper-case
|
69
|
-
# `Q` argument for their 1–100 integer quality factor,
|
70
|
-
# and my VipsSave module's `:ATTRIBUTES` additionally aliases it
|
71
|
-
# to the more typical `quality` to provide consistent UX
|
72
|
-
# with other attributes from VIPS and other sources.
|
73
|
-
# https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-jpegsave
|
74
|
-
#
|
75
|
-
# VIPS also provides our example of the need for attribute-value equivalents,
|
76
|
-
# such as how it only accepts the spelling of "centre" and not "center"
|
77
|
-
# like myself and many millions of other people will reflexively enter :)
|
78
|
-
# https://libvips.github.io/libvips/API/current/libvips-conversion.html#VipsInteresting
|
79
|
-
def self.so_deep(fragment)
|
80
|
-
fragment.each_with_object(Array[]) { |(attribute, raw), to_merge|
|
81
|
-
# Each attribute's :raw may be an object (probably a Symbol),
|
82
|
-
# a Set (e.g. of aliases), or nil (for all values in a Set.to_hash)
|
83
|
-
case raw
|
84
|
-
when Set then raw.add(attribute)
|
85
|
-
when NilClass then [attribute]
|
86
|
-
else [attribute]
|
87
|
-
end.each{ |equivalent|
|
88
|
-
to_merge << [equivalent, attribute]
|
89
|
-
}
|
90
|
-
}.to_h
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns a block that will define methods in a given context
|
94
|
-
# such that when the given context is included/extended/prepended
|
95
|
-
# we will also merge our DD attributes into the new layer.
|
96
|
-
Injection_Of_Love = Proc.new { |otra|
|
97
|
-
# These are the methods that actively perform the include/extend/prepend process.
|
98
|
-
[:append_features, :prepend_features, :extend_object].each { |m|
|
99
|
-
otra.define_singleton_method(m) do |winter|
|
100
|
-
# Perform the normal include/extend/prepend that will mask our constants.
|
101
|
-
super(winter)
|
102
|
-
|
103
|
-
# Get new values to override masked constants.
|
104
|
-
pile = Cooltrainer::DistorteD::InjectionOfLove::trip_machine(winter)
|
105
|
-
|
106
|
-
# Record each constant individually as well as the entire pile.
|
107
|
-
# This doesn't currently get used, as this :class_variable_set call
|
108
|
-
# is broken in KRI:
|
109
|
-
# - https://bugs.ruby-lang.org/issues/7475
|
110
|
-
# - https://bugs.ruby-lang.org/issues/8297
|
111
|
-
# - https://bugs.ruby-lang.org/issues/11022
|
112
|
-
winter.singleton_class.class_variable_set(AFTERPARTY, pile)
|
113
|
-
pile.each_pair{ |k, v|
|
114
|
-
if winter.singleton_class.const_defined?(k, false)
|
115
|
-
# Since we are setting constants in the singleton_class
|
116
|
-
# we must remove any old ones first to avoid a warning.
|
117
|
-
winter.singleton_class.send(:remove_const, k)
|
118
|
-
end
|
119
|
-
winter.singleton_class.const_set(k, v)
|
120
|
-
}
|
121
|
-
end
|
122
|
-
}
|
123
|
-
# These are the callback methods called after the above methods fire.
|
124
|
-
# Use them to perpetuate our merge by calling the thing that calls us :)
|
125
|
-
[:included, :prepended, :extended].each { |m|
|
126
|
-
otra.define_singleton_method(m) do |winter|
|
127
|
-
Cooltrainer::DistorteD::InjectionOfLove::Injection_Of_Love.call(winter)
|
128
|
-
super(winter)
|
129
|
-
end
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
# Returns an instance-level copy of the complete attribute pile.
|
134
|
-
def trip_machine
|
135
|
-
@DistorteD ||= Cooltrainer::DistorteD::InjectionOfLove::trip_machine(self.singleton_class)
|
136
|
-
end
|
137
|
-
|
138
|
-
# Builds the attribute pile (e.g. suported atrs, values, defaults, etc) for any given scope.
|
139
|
-
def self.trip_machine(scope)
|
140
|
-
attribute_aliases = Hash[]
|
141
|
-
alias_attributes = Hash[]
|
142
|
-
values = Hash[]
|
143
|
-
defaults = Hash[]
|
144
|
-
|
145
|
-
scope&.ancestors.each { |otra|
|
146
|
-
DISTORTED_CONSTANTS.each { |invitation| # OUT OF CONTROL / MY WHEELS IN CONSTANT MOTION
|
147
|
-
if otra.const_defined?(invitation)
|
148
|
-
part = otra.const_get(invitation) rescue Hash[]
|
149
|
-
|
150
|
-
if invitation == :ATTRIBUTES
|
151
|
-
# Support both alias-to-attribute and attribute-to-aliases
|
152
|
-
attribute_aliases.merge!(part) { |invitation, old, new|
|
153
|
-
if old.nil?
|
154
|
-
new.nil? ? Set[invitation] : Set[new]
|
155
|
-
elsif new.nil?
|
156
|
-
old
|
157
|
-
elsif new.is_a?(Enumerable)
|
158
|
-
old.merge(new)
|
159
|
-
else
|
160
|
-
old << new
|
161
|
-
end
|
162
|
-
}
|
163
|
-
alias_attributes.merge!(Cooltrainer::DistorteD::InjectionOfLove::so_deep(part))
|
164
|
-
elsif invitation == :ATTRIBUTES_VALUES
|
165
|
-
# Regexes currently override Enumerables
|
166
|
-
to_merge = {}
|
167
|
-
part.each_pair { |attribute, values|
|
168
|
-
if values.is_a?(Regexp)
|
169
|
-
to_merge.update(attribute => values)
|
170
|
-
else
|
171
|
-
to_merge.update(attribute => Cooltrainer::DistorteD::InjectionOfLove::so_deep(values))
|
172
|
-
end
|
173
|
-
}
|
174
|
-
values.merge!(to_merge)
|
175
|
-
elsif invitation == :ATTRIBUTES_DEFAULT
|
176
|
-
defaults.merge!(part)
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
return {
|
184
|
-
:ATTRIBUTE_ALIASES => attribute_aliases,
|
185
|
-
:ALIAS_ATTRIBUTES => alias_attributes,
|
186
|
-
:ATTRIBUTES_VALUES => values,
|
187
|
-
:ATTRIBUTES_DEFAULT => defaults,
|
188
|
-
}
|
189
|
-
end
|
190
|
-
|
191
|
-
# Returns a value for any attribute.
|
192
|
-
# In order of priority, that means:
|
193
|
-
# - A user-given value (Liquid, CLI, etc) iff it passes a validity check,
|
194
|
-
# - the default value if the given value is not in the accepted Set,
|
195
|
-
# - nil for unset attributes with no default defined.
|
196
|
-
def abstract(argument)
|
197
|
-
# Reject any unknown arguments.
|
198
|
-
if trip_machine.dig(:ATTRIBUTE_ALIASES)&.keys.include?(argument)
|
199
|
-
alias_possibilities = trip_machine.dig(:ATTRIBUTE_ALIASES)&.dig(argument) || Set[]
|
200
|
-
possibilities = user_arguments&.keys.to_set & alias_possibilities
|
201
|
-
|
202
|
-
# How many matching user-defined attributes are there for our aliases?
|
203
|
-
case possibilities.length
|
204
|
-
when 0
|
205
|
-
# None; take the default.
|
206
|
-
trip_machine.dig(:ATTRIBUTES_DEFAULT)&.dig(argument)
|
207
|
-
when 1
|
208
|
-
# One; does it look valid?
|
209
|
-
is_valid = false
|
210
|
-
user_value = user_arguments&.dig(argument)
|
211
|
-
|
212
|
-
# Supported values may be declared as:
|
213
|
-
# - A Hash of values-and-their-aliases to values.
|
214
|
-
# - A Regex.
|
215
|
-
# - nil for freeform input.
|
216
|
-
valid_value = trip_machine.dig(:ATTRIBUTES_VALUES)&.dig(argument)
|
217
|
-
if valid_value.is_a?(Enumerable)
|
218
|
-
if valid_value.include?(user_value)
|
219
|
-
is_valid = true
|
220
|
-
end
|
221
|
-
elsif valid_value.is_a?(Regexp)
|
222
|
-
if valid_value.match(user_value.to_s)
|
223
|
-
is_valid = true
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
# Return a valid user value, a default, or nil if all else fails.
|
228
|
-
if is_valid
|
229
|
-
# TODO: boolean casting
|
230
|
-
user_value
|
231
|
-
else
|
232
|
-
trip_machine.dig(:ATTRIBUTES_DEFAULT)&.dig(argument)
|
233
|
-
end
|
234
|
-
|
235
|
-
else # case user_values.length
|
236
|
-
# Two or more; what do??
|
237
|
-
raise RuntimeError("Can't have multiple settings for #{argument} and its aliases.")
|
238
|
-
end
|
239
|
-
else
|
240
|
-
# The programmer asked for the value of an attribute that is
|
241
|
-
# not supported by its MediaMolecule. This is most likely a bug.
|
242
|
-
raise RuntimeError("#{argument} is not supported for #{@name}")
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
|
247
|
-
end
|