Module: RailsAssist::Files::Methods

Included in:
RailsAssist::Files, RailsAssist::Files
Defined in:
lib/rails_assist/files.rb

Overview

we depend on the Directories module doing some of the hard work!

Constant Summary collapse

RYBY_FILES =
'**/*.rb'

Instance Method Summary collapse

Instance Method Details

#all_filepaths(expr = nil) ⇒ Object



26
27
28
29
# File 'lib/rails_assist/files.rb', line 26

def all_filepaths expr=nil
  pattern = "#{RailsAssist::Directory::Root.root_dirpath}/**/*.*"
  FileList[pattern].to_a.grep_it expr 
end

#all_files(expr = nil) ⇒ Object



31
32
33
# File 'lib/rails_assist/files.rb', line 31

def all_files expr=nil
  all_filepaths(expr).to_files
end

#app_filepaths(expr = nil) ⇒ Object



35
36
37
# File 'lib/rails_assist/files.rb', line 35

def app_filepaths expr=nil
  rails_app_files(:app).grep_it expr
end

#app_files(expr = nil) ⇒ Object



39
40
41
# File 'lib/rails_assist/files.rb', line 39

def app_files expr=nil
  app_filepaths(expr).to_files
end

#filepaths_from(*types) {|the_files| ... } ⇒ Object

files_from :model, :controller, :matching => /user/

Yields:

  • (the_files)


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails_assist/files.rb', line 44

def filepaths_from *types, &block
  expr = last_option(types)[:matching]
  the_files = types.inject([])  do |files, type|
    method = :"#{type}_files"
    files_found = send(method, expr) if respond_to?(method)
    files_found = RailsAssist::Artifact::Files.send(method, expr) if RailsAssist::Artifact::Files.respond_to?(method)
    files + files_found
  end.compact
  yield the_files if block
  the_files
end

#files_from(*types, &block) ⇒ Object



56
57
58
# File 'lib/rails_assist/files.rb', line 56

def files_from *types, &block
  filepaths_from(*types, &block).to_files
end

#rails_app_filepaths(type = :app, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rails_assist/files.rb', line 13

def rails_app_filepaths type = :app, options = {}
  type = (type =~ /ss/) ? type : type.to_s.singularize
  dir = RailsAssist::Directory.send "#{type}_dirpath"
  expr = options[:expr]
  file_pattern = options[:pattern] || RYBY_FILES
  pattern = "#{dir}/#{file_pattern}"
  FileList[pattern].to_a.grep_it expr
end

#rails_app_files(type = :app, options = {}) ⇒ Object



22
23
24
# File 'lib/rails_assist/files.rb', line 22

def rails_app_files type = :app, options = {}
  rails_app_filepaths(type, options).to_files
end

#with_filepaths_from(type, expr = nil, &block) ⇒ Object



60
61
62
63
# File 'lib/rails_assist/files.rb', line 60

def with_filepaths_from type, expr=nil, &block
  method = "#{type}_files"
  send method, expr, &block if respond_to?(method)
end

#with_files_from(type, expr = nil, &block) ⇒ Object



65
66
67
# File 'lib/rails_assist/files.rb', line 65

def with_files_from type, expr=nil, &block
  with_filepaths_from(type, expr=nil, &block).to_files
end