Skip to content

Commit

Permalink
Merge pull request #23 from metricfu/remove_rubygems_require
Browse files Browse the repository at this point in the history
Remove rubygems require & fixing a bunch of Ruby warnings
  • Loading branch information
evjan committed Aug 25, 2013
2 parents 8287039 + 1c848c5 commit eaae272
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
15 changes: 6 additions & 9 deletions lib/roodi/checks/abc_metric_method_check.rb
Expand Up @@ -35,23 +35,20 @@ def evaluate_start(node)
private

def count_assignments(node)
count = 0
count = count + 1 if assignment?(node)
node.children.each {|node| count += count_assignments(node)}
count = assignment?(node) ? 1 : 0
node.children.each {|child_node| count += count_assignments(child_node)}
count
end

def count_branches(node)
count = 0
count = count + 1 if branch?(node)
node.children.each {|node| count += count_branches(node)}
count = branch?(node) ? 1 : 0
node.children.each {|child_node| count += count_branches(child_node)}
count
end

def count_conditionals(node)
count = 0
count = count + 1 if conditional?(node)
node.children.each {|node| count += count_conditionals(node)}
count = conditional?(node) ? 1 : 0
node.children.each {|child_node| count += count_conditionals(child_node)}
count
end

Expand Down
4 changes: 2 additions & 2 deletions lib/roodi/checks/check.rb
Expand Up @@ -28,8 +28,8 @@ def initialize
NODE_TYPES.each do |node|
start_node_method = "evaluate_start_#{node}"
end_node_method = "evaluate_end_#{node}"
define_method(start_node_method) { |node| return } unless self.respond_to?(start_node_method)
define_method(end_node_method) { |node| return } unless self.respond_to?(end_node_method)
define_method(start_node_method) { |start_node| return } unless self.respond_to?(start_node_method)
define_method(end_node_method) { |end_node| return } unless self.respond_to?(end_node_method)
end

def position(offset = 0)
Expand Down
6 changes: 3 additions & 3 deletions lib/roodi/checks/method_name_check.rb
Expand Up @@ -3,17 +3,17 @@
module Roodi
module Checks
# Checks a method name to make sure it matches the specified pattern.
#
#
# Keeping to a consistent nameing convention makes your code easier to read.
class MethodNameCheck < NameCheck

DEFAULT_PATTERN = /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/

def initialize
super()
self.pattern = DEFAULT_PATTERN
end

def interesting_nodes
[:defn]
end
Expand Down
15 changes: 7 additions & 8 deletions lib/roodi/core/parser.rb
@@ -1,18 +1,17 @@
require 'rubygems'
require 'ruby_parser'
require 'rbconfig'

module Roodi
module Core
class Parser
def parse(content, filename)
silence_stream(STDERR) do
silence_stream(STDERR) do
return silent_parse(content, filename)
end
end

private

def silence_stream(stream)
old_stream = stream.dup
stream.reopen(null_stream_output)
Expand All @@ -21,16 +20,16 @@ def silence_stream(stream)
ensure
stream.reopen(old_stream)
end

def silent_parse(content, filename)
@parser ||= RubyParser.new
@parser.parse(content, filename)
end

def null_stream_output
null_output_for_platform(RbConfig::CONFIG['host_os'])
end

def null_output_for_platform(host_os)
case host_os
when windows_host_os_matcher
Expand All @@ -39,7 +38,7 @@ def null_output_for_platform(host_os)
'/dev/null'
end
end

def windows_host_os_matcher
/mingw|mswin32|cygwin/o
end
Expand Down
2 changes: 1 addition & 1 deletion lib/roodi/core/runner.rb
Expand Up @@ -60,7 +60,7 @@ def errors
def parse(filename, content)
begin
Parser.new.parse(content, filename)
rescue Exception => e
rescue Exception
parsing_errors << "#{filename} looks like it's not a valid Ruby file."
nil
end
Expand Down
5 changes: 2 additions & 3 deletions lib/roodi/core/visitable_sexp.rb
@@ -1,4 +1,3 @@
require 'rubygems'
require 'sexp'

class Sexp
Expand All @@ -13,11 +12,11 @@ def node_type
def children
find_all { | sexp | Sexp === sexp }
end

def is_language_node?
first.class == Symbol
end

def visitable_children
parent = is_language_node? ? sexp_body : self
parent.children
Expand Down

0 comments on commit eaae272

Please sign in to comment.