Skip to content

Commit

Permalink
moving fundamental helper methods from command_helpers to base_helprs…
Browse files Browse the repository at this point in the history
… (set_file_and_dir_locals() and no_color())
  • Loading branch information
banister committed May 4, 2011
1 parent 1e655ed commit 676cf20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 17 additions & 0 deletions lib/pry/helpers/base_helpers.rb
Expand Up @@ -14,6 +14,15 @@ def silence_warnings
end
end

# turn off color for duration of block
def no_color(&block)
old_color_state = Pry.color
Pry.color = false
yield
ensure
Pry.color = old_color_state
end

def gem_installed?(gem_name)
require 'rubygems'
!!Gem.source_index.find_name(gem_name).first
Expand All @@ -26,6 +35,14 @@ def command_dependencies_met?(options)
end
end

def set_file_and_dir_locals(file_name)
return if !target
$_file_temp = File.expand_path(file_name)
$_dir_temp = File.dirname($_file_temp)
target.eval("_file_ = $_file_temp")
target.eval("_dir_ = $_dir_temp")
end

def stub_proc(name, options)
gems_needed = Array(options[:requires_gem])
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
Expand Down
8 changes: 0 additions & 8 deletions lib/pry/helpers/command_helpers.rb
Expand Up @@ -23,14 +23,6 @@ def meth_name_from_binding(b)
end
end

def set_file_and_dir_locals(file_name)
return if !target
$_file_temp = File.expand_path(file_name)
$_dir_temp = File.dirname($_file_temp)
target.eval("_file_ = $_file_temp")
target.eval("_dir_ = $_dir_temp")
end

def add_line_numbers(lines, start_line)
line_array = lines.each_line.to_a
line_array.each_with_index.map do |line, idx|
Expand Down

0 comments on commit 676cf20

Please sign in to comment.