dead_code_terminator 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: ff515ae6bc72607dd216a1889d5e246d390c2c6bc2ccb9a3662509bac6b2a678
4
- data.tar.gz: 7b4fc0bb7d5b5a6c79201f8dfb3ba94c6aef8e3d27fb0187f20d19df86fe72cd
3
+ metadata.gz: 120030c3b768640a90d8b8d3f762280835dc107e03214c47a53611d39e30a7a7
4
+ data.tar.gz: 29cc7f27dc056671f4c7104ff653020e64842b010a386e9095ce9cf75020a80c
5
5
  SHA512:
6
- metadata.gz: 5f19644fbd69e00c3145263430e7425f9f0b2b843a34fa1feba5c71c5b4ae816ffef764c10650e75a77e71bf9d00be509fb31a56940387083a4a53205d273d93
7
- data.tar.gz: 0f346607cc9e18bd54e546c1e725ef5e925ab90f02fbcf1d17c37846c44497040696620644362fd6d02ba00e5bcb3f321ba584e6cabbe8653326e3d5727a96c4
6
+ metadata.gz: 3bef01523a2c5803bae4d3aecb43878195b7e6138656e0bb5d686d6d28ce7a351aec3bcfe06b760dc3fd2d53441d34e1a293a14461157b04a2da9c6450a93364
7
+ data.tar.gz: fa2641062b631410568e8319781a83dd05341364acfbf961dec5fae09ecfa5d92b7adb87ca5c088af5cb3500dd6445ab2a774fa52c49e2927a51657cac97f8c7
data/README.md CHANGED
@@ -7,24 +7,37 @@
7
7
  This acts like [webpack's DefinePlugin](https://webpack.js.org/plugins/define-plugin/) with minification pass. It allows to eliminate dead code statically, which can be required by regulations.
8
8
 
9
9
  ```ruby
10
- if ENV['PRODUCTION']
11
- :then_branch
10
+ value = if ENV['FLAG']
11
+ :then_branch
12
12
  else
13
- :else_branch
13
+ value2 = unless ENV['PRODUCTION']
14
+ :then_branch
15
+ else
16
+ ENV['RUNTIME'] ? :else1 : :else2
17
+ end
14
18
  end
15
19
  ```
16
20
 
17
21
  ```ruby
18
-
19
- :then_branch
22
+ # returns a valid ruby code string back with statically evaluated conditions
23
+ DeadCodeTerminator.strip(string, env: { "PRODUCTION" => true, "FLAG" => false })
24
+ ```
20
25
 
21
-
26
+ ```ruby
27
+ value =
22
28
 
29
+
30
+ value2 =
31
+
32
+
33
+ ENV['RUNTIME'] ? :else1 : :else2
23
34
  ```
24
35
 
25
36
  Note: it keeps *precise* code locations (including whitespaces and line-breaks).
26
37
  So if you have hotfix patches from upstream - they'll be applied without conflicts.
27
38
 
39
+ Other example can be found in [specs](https://github.com/razum2um/dead_code_terminator/blob/master/spec/dead_code_terminator_spec.rb)
40
+
28
41
  ## TODO
29
42
 
30
43
  - builtin file tree processing
@@ -70,6 +70,8 @@ module DeadCodeTerminator
70
70
 
71
71
  # :(
72
72
  def count_spaces_before_first_line_of_static_if_branch
73
+ return 0 if total_lines == 1
74
+
73
75
  (begin_pos - 1).downto(0).take_while do |pos|
74
76
  line_for_position_of_static_if_branch(pos) == from_line
75
77
  end.size
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadCodeTerminator
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_code_terminator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Bokov