Class: RoCommands::FileActions

Inherits:
Base show all
Defined in:
lib/ro_commands/file_actions.rb

Instance Method Summary collapse

Methods inherited from Base

describe, inherited, method_added, meths, start, usage

Methods included from Bash

#_bash, #add_time, #bash, #bash_capture, #bash_capture_array, #bash_lines, #bash_per, #bash_system, #bundle_exec, #err, err, #handle_path, #kernel_system, out, #out, #status, status

Instance Method Details

#find(dir, keyword = nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/ro_commands/file_actions.rb', line 9

def find(path, keyword)
  fs = Find.find(path).map do |file|
    basename = File.basename(file).gsub(%r{\.\w+$}, "")
  end
  fs.grep(%r{#{keyword}})
  Out.out "#{fs}   file:#{::File.basename __FILE__} line:#{__LINE__}", "green"
end

#find_railscasts(video_name) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/ro_commands/file_actions.rb', line 54

def find_railscasts(video_name)
  Find.find('/media/zxr/New-Volume/TDDOWNLOAD/railscasts/').each do |path|
    if path[Regexp.new video_name]
      paths << path
    end
  end

  puts paths
  paths
end

#grep(keyword, path = nil, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ro_commands/file_actions.rb', line 19

def grep(keyword, path=nil, options={})
  if options.is_a?(String)
    options = convert_options options
  end

  @keyword = keyword
  @path = path || Dir.pwd

  @options = options

  if @options[:verbose]
    @match_files = []
    _grep_verbose
    puts_match_files
  else
    _grep()
  end
end

#rename(from, to_keyword) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/ro_commands/file_actions.rb', line 67

def rename(from, to_keyword)
  basename, ext = RoFile.basename_ext(from)
  replace_keyword = basename
  to = from.gsub(replace_keyword, to_keyword)
  unless to == from
    Out.table("renaming", "from #{from} to #{to}  ","file:#{File.basename __FILE__} line:#{__LINE__}")
    FileUtils.mv(from, to)
  end
end