0

We use the same monolithic code for two different contexts based on an environment variable.

For example, each class is as follows, where global variable context is assigned "A" or "B" based on an environment variable at initialization:

class Demo
  class << self
    def demo_method(xy, z)
      if context == "A"
        p "from app A"
      else
        p "from app B"
      end
    end
  end
end

I want a tool that splits the whole code based on the variable, and generates two different code bases:

From our example, app A code will look like:

class Demo
  class << self
    def demo_method(xy, z)
      p "from app A"
    end
  end
end

and app B code will look like:

class Demo
  class << self
    def demo_method(xy, z)
      p "from app B"
    end
  end
end
sawa
  • 165,429
  • 45
  • 277
  • 381
claudius
  • 1,112
  • 1
  • 10
  • 23
  • What is your question? – sawa Feb 01 '16 at 10:33
  • It looks like you want to simplify the program based on a "feature", in your case, *context == "A"* or *context != "A"*. Does the example at the end of this linked page make sense? http://www.semdesigns.com/Products/DMS/DMSRewriteRules.html If it does, I can respond more fully. – Ira Baxter Feb 01 '16 at 10:34
  • @sawa: His question is perfectly clear; he wants to know how he can partition his code base automatically. – Ira Baxter Feb 01 '16 at 10:35
  • yes, this makes sense. But, @IraBaxter I am looking for an open source/free tool. Anyways, can you please elaborate. – claudius Feb 01 '16 at 10:51
  • just write a script that recurses through your app files, looks for such "if context=='a'" lines and creates separate files. i doubt there exists a tool that would fit your needs. – Kimmo Lehto Feb 01 '16 at 13:03
  • This is the same problem as to find out -by program X- that another program (Y) would run properly. Which is impossible, without running program Y. – karatedog Feb 02 '16 at 01:15
  • @karatedog: The problem is defined over trees. You can compare them without caring if they compute the same thing, and yes, sometimes you'll two trees that look the same that don't. But in my considerable experience using CloneDR, if the clones have any mass (e.g., several lines of code), pretty much they are computing the "same" thing conceptually. Slight differences in the trees are easily interpreted as parameters. – Ira Baxter Feb 04 '16 at 07:21
  • @claudius: did you check the example on the provided link page? It shows how to use a program transformation tool to simplify away an unwanted condition. I think this is the effect you are looking for. – Ira Baxter Mar 20 '16 at 10:22

0 Answers0