fixer_upper 0.2.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/.rubocop.yml +0 -3
- data/lib/fixer_upper/renovation.rb +26 -20
- data/lib/fixer_upper/version.rb +1 -1
- data/lib/fixer_upper.rb +19 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f17d076ad0560c75356d33ca5492fbb5adb288bc
|
4
|
+
data.tar.gz: 239fc8b0a65b17a08134ed437a7286060b68bdf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee1c19957a62ebb59c34cca172fb9a5f2babc992309672e83a75b8396c17dc25932e389309a5cce5f26476cf99f1d8682479b6e2bc031581b87f76218d07f0f8
|
7
|
+
data.tar.gz: 3c2ca497612378216dc759246b7c2052065061dd6cbf326b3caaae7703702c8d0826ba30490f95510d95ef78d0faaa0312156c36cfeedc9070aab936696d48b5
|
data/.rubocop.yml
CHANGED
@@ -5,20 +5,25 @@ class FixerUpper
|
|
5
5
|
@options = options
|
6
6
|
end
|
7
7
|
|
8
|
-
def renovate(filepath
|
9
|
-
|
8
|
+
def renovate(filepath:, text: nil, options:, bang:)
|
9
|
+
contents = file_contents(filepath, text)
|
10
10
|
|
11
|
-
diy(
|
11
|
+
diy(
|
12
|
+
text: contents,
|
13
|
+
engines: extensions(filepath).reverse,
|
14
|
+
options: options,
|
15
|
+
bang: bang
|
16
|
+
)
|
12
17
|
end
|
13
18
|
|
14
|
-
def diy(text
|
15
|
-
|
19
|
+
def diy(text:, engines:, options:, bang:)
|
20
|
+
engines.reduce(text) do |memo, engine_name|
|
21
|
+
engine = find_engine(engine_name, bang)
|
16
22
|
|
17
|
-
|
18
|
-
default_options = @options[engine]
|
23
|
+
merged_options = options_for_engine(engine_name, options)
|
19
24
|
|
20
|
-
if
|
21
|
-
engine.call(memo, **
|
25
|
+
if merged_options.any? && engine.method(:call).parameters.count >= 2
|
26
|
+
engine.call(memo, **merged_options)
|
22
27
|
else
|
23
28
|
engine.call(memo)
|
24
29
|
end
|
@@ -27,17 +32,18 @@ class FixerUpper
|
|
27
32
|
|
28
33
|
private
|
29
34
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
next engine_request
|
34
|
-
end
|
35
|
+
def options_for_engine(engine_name, local_options)
|
36
|
+
default_options = @options[engine_name] || {}
|
37
|
+
specific_options = local_options[engine_name.to_sym] || {}
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
default_options.merge(specific_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_engine(engine_name, bang)
|
43
|
+
if bang
|
44
|
+
engine_or_raise(engine_name)
|
45
|
+
else
|
46
|
+
engine_or_nil(engine_name)
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -49,7 +55,7 @@ class FixerUpper
|
|
49
55
|
found_engine = @registry[engine_name]
|
50
56
|
|
51
57
|
if found_engine
|
52
|
-
|
58
|
+
found_engine
|
53
59
|
else
|
54
60
|
raise Error::EngineNotFound, "unknown engine: `#{engine_name}`"
|
55
61
|
end
|
data/lib/fixer_upper/version.rb
CHANGED
data/lib/fixer_upper.rb
CHANGED
@@ -12,28 +12,37 @@ class FixerUpper
|
|
12
12
|
def register(*keys, to:, **options)
|
13
13
|
keys.each do |key|
|
14
14
|
@engine_registry[key] = to
|
15
|
+
@options_registry[key] = options
|
15
16
|
end
|
16
|
-
|
17
|
-
@options_registry[to] = options
|
18
17
|
end
|
19
18
|
|
20
19
|
def for(key)
|
21
20
|
@engine_registry[key]
|
22
21
|
end
|
23
22
|
|
24
|
-
def renovate(filepath, contents = nil)
|
25
|
-
@renovation.renovate(
|
23
|
+
def renovate(filepath, contents = nil, **options)
|
24
|
+
@renovation.renovate(
|
25
|
+
filepath: filepath,
|
26
|
+
text: contents,
|
27
|
+
options: options,
|
28
|
+
bang: false
|
29
|
+
)
|
26
30
|
end
|
27
31
|
|
28
|
-
def renovate!(filepath, contents = nil)
|
29
|
-
@renovation.renovate(
|
32
|
+
def renovate!(filepath, contents = nil, **options)
|
33
|
+
@renovation.renovate(
|
34
|
+
filepath: filepath,
|
35
|
+
text: contents,
|
36
|
+
options: options,
|
37
|
+
bang: true
|
38
|
+
)
|
30
39
|
end
|
31
40
|
|
32
|
-
def diy(text, engines)
|
33
|
-
@renovation.diy(text, engines, bang: false)
|
41
|
+
def diy(text, *engines, **options)
|
42
|
+
@renovation.diy(text: text, engines: engines, options: options, bang: false)
|
34
43
|
end
|
35
44
|
|
36
|
-
def diy!(text, engines)
|
37
|
-
@renovation.diy(text, engines, bang: true)
|
45
|
+
def diy!(text, *engines, **options)
|
46
|
+
@renovation.diy(text: text, engines: engines, options: options, bang: true)
|
38
47
|
end
|
39
48
|
end
|