fixer_upper 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 222ca8f8dffc3a73359f8676c8ec6818e410166e
4
- data.tar.gz: 7d31e42a287ebd8226bb647c982f755fcad11ecf
3
+ metadata.gz: f17d076ad0560c75356d33ca5492fbb5adb288bc
4
+ data.tar.gz: 239fc8b0a65b17a08134ed437a7286060b68bdf1
5
5
  SHA512:
6
- metadata.gz: e6146fa503db14d781810be48d71511ddab8f1ccf96e6729dbe81936e5ab02ccb728180dcc7a03bd48fd02a9cecd9a4f46f80fb816b282f913d21d02a88d4d65
7
- data.tar.gz: bb463a18b1bfd1e6a04fe9ccd49b462af80882380515c6c5d495c84b64de4001414c9c70fad851045556d589b84fcbb8c737e4ee0fc3810574bdc3b7a3621fdd
6
+ metadata.gz: ee1c19957a62ebb59c34cca172fb9a5f2babc992309672e83a75b8396c17dc25932e389309a5cce5f26476cf99f1d8682479b6e2bc031581b87f76218d07f0f8
7
+ data.tar.gz: 3c2ca497612378216dc759246b7c2052065061dd6cbf326b3caaae7703702c8d0826ba30490f95510d95ef78d0faaa0312156c36cfeedc9070aab936696d48b5
data/.rubocop.yml CHANGED
@@ -47,8 +47,5 @@ Style/StringLiterals:
47
47
  Style/StringLiteralsInInterpolation:
48
48
  Enabled: false
49
49
 
50
- Style/TrailingCommaInArguments:
51
- EnforcedStyleForMultiline: comma
52
-
53
50
  Style/TrailingCommaInLiteral:
54
51
  EnforcedStyleForMultiline: comma
@@ -5,20 +5,25 @@ class FixerUpper
5
5
  @options = options
6
6
  end
7
7
 
8
- def renovate(filepath, contents, bang:)
9
- text = file_contents(filepath, contents)
8
+ def renovate(filepath:, text: nil, options:, bang:)
9
+ contents = file_contents(filepath, text)
10
10
 
11
- diy(text, *extensions(filepath).reverse, bang: bang)
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, *engines, bang:)
15
- mapped_engines = map_engines(engines, bang: bang).compact
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
- mapped_engines.reduce(text) do |memo, engine|
18
- default_options = @options[engine]
23
+ merged_options = options_for_engine(engine_name, options)
19
24
 
20
- if default_options && engine.method(:call).parameters.count >= 2
21
- engine.call(memo, **default_options)
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 map_engines(engines, bang:)
31
- engines.map do |engine_request|
32
- if engine_request.respond_to?(:call)
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
- if bang
37
- engine_or_raise(engine_request)
38
- else
39
- engine_or_nil(engine_request)
40
- end
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
- file_contents
58
+ found_engine
53
59
  else
54
60
  raise Error::EngineNotFound, "unknown engine: `#{engine_name}`"
55
61
  end
@@ -1,3 +1,3 @@
1
1
  class FixerUpper
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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(filepath, contents, bang: false)
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(filepath, contents, bang: true)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixer_upper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn