Project

ifdef

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Parse source code, looking for conditional statements and replace brances that are known to be false.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 3.1

Runtime

~> 2.2
 Project Readme

Ifdef

Ifdef parses Ruby files, removing conditional branches that will never execute. You provide a set of statements that are known to be true or false (Eg. Rails.production? will be true in production), and Ifdef uses that to decide which branches will run and which to delete.

Ifdef analyses conditionals for if, unless and ternary statements. It can handle some logic in conditionals. For example, if Rails.production? is true, Ifdef will understand that !Rails.production? is false, and Rails.production? || some_other_statement is true. A statement is only considered to be true if it is known to be true. For example Rails.production? && some_other_statement will be true or false depending on the value of some_other_statement. Ifdef will not rewrite branches of this conditional.

Usage

Usage: ifdef [options] file
-a, --true=MANDATORY             A comma separated list of statements to treat as true
-b, --false=MANDATORY            A comma separated list of statements to treat as false
-c, --config=MANDATORY           The path to a JSON truth config file
-h, --help                       Show this message

Example

ifdef -a "Rails.production?" -b "Rails.test?" ./app/controllers/application_controller.rb

Installing

  • gem install ifdef