Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MVC experiment continues. Cleaner delegation.

  • Loading branch information...
commit 362ab2ea03c997798b900c27a29c2de39a82508b 1 parent d7dfdb3
@gilesbowkett authored
View
1  lib/code_base.rb
@@ -7,7 +7,6 @@ def parse(dir)
extract_definitions(@method_definitions, (ParseTree.translate File.read(filename)), filename)
end
end
- alias :dir= :parse
def extract_definitions(accumulator, nodes, filename)
case nodes
when Array
View
24 lib/controller.rb
@@ -0,0 +1,24 @@
+class Towelie
+ class << self
+ def delegate_thru_view(*method_names)
+ method_names.each do |method_name|
+ class_eval <<-METHOD
+ def #{method_name}(*args)
+ @view.to_ruby(@model.#{method_name}(*args))
+ end
+ METHOD
+ end
+ end
+ def delegate_thru_model(*method_names)
+ method_names.each do |method_name|
+ class_eval <<-METHOD
+ def #{method_name}(*args)
+ @model.#{method_name}(*args)
+ end
+ METHOD
+ end
+ end
+ end
+ delegate_thru_model :parse, :duplication?, :method_definitions
+ delegate_thru_view :duplicated, :unique, :homonyms, :diff
+end
View
23 lib/towelie.rb
@@ -9,6 +9,7 @@
require "#{File.dirname(__FILE__) + "/"}node_analysis"
require "#{File.dirname(__FILE__) + "/"}model"
require "#{File.dirname(__FILE__) + "/"}view"
+require "#{File.dirname(__FILE__) + "/"}controller"
class Towelie
@@ -16,28 +17,6 @@ def initialize
@model = Model.new
@view = View.new
end
- def parse(dir)
- @model.parse(dir)
- end
- alias :dir= :parse
- def duplication?(dir)
- @model.duplication?(dir)
- end
- def method_definitions
- @model.method_definitions
- end
- def duplicated(dir)
- @view.to_ruby(@model.duplicated(dir))
- end
- def unique(dir)
- @view.to_ruby(@model.unique(dir))
- end
- def homonyms(dir)
- @view.to_ruby(@model.homonyms(dir))
- end
- def diff(threshold)
- @view.to_ruby(@model.diff(threshold))
- end
end
# most methods need a dir loaded. therefore we should have an object which takes a dir (and probably
View
2  spec/towelie_spec.rb
@@ -99,7 +99,7 @@ def foo
@towelie.duplication?("spec/non_duplicating_data").should be_false
end
it "extracts :defn nodes" do
- @towelie.dir = "spec/test_data"
+ @towelie.parse("spec/test_data")
@towelie.method_definitions.should == @the_nodes
@towelie.parse("spec/classes_modules")
@towelie.method_definitions.should == @the_nodes
Please sign in to comment.
Something went wrong with that request. Please try again.