Module: Rails3::Assist::Files::Methods
- Included in:
- Rails3::Assist::Files, Rails3::Assist::Files
- Defined in:
- lib/rails3_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
- #all_files(expr = nil) ⇒ Object
- #app_files(expr = nil) ⇒ Object
-
#files_from(*types) {|the_files| ... } ⇒ Object
files_from :model, :controller, :matching => /user/.
- #rails_app_files(type = :app, options = {}) ⇒ Object
- #with_files_from(type, expr = nil, &block) ⇒ Object
Instance Method Details
#all_files(expr = nil) ⇒ Object
21 22 23 24 |
# File 'lib/rails3_assist/files.rb', line 21 def all_files expr=nil pattern = "#{Rails3::Assist::Directory::Root.root_dir}/**/*.*" FileList[pattern].to_a.grep_it expr end |
#app_files(expr = nil) ⇒ Object
26 27 28 |
# File 'lib/rails3_assist/files.rb', line 26 def app_files expr=nil rails_app_files(:app).grep_it expr end |
#files_from(*types) {|the_files| ... } ⇒ Object
files_from :model, :controller, :matching => /user/
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails3_assist/files.rb', line 31 def files_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 = Rails3::Assist::Artifact::Files.send(method, expr) if Rails3::Assist::Artifact::Files.respond_to?(method) files + files_found end.compact yield the_files if block the_files end |
#rails_app_files(type = :app, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rails3_assist/files.rb', line 13 def rails_app_files type = :app, = {} dir = Rails3::Assist::Directory.send "#{type.to_s.singularize}_dir" expr = [:expr] file_pattern = [:pattern] || RYBY_FILES pattern = "#{dir}/#{file_pattern}" FileList[pattern].to_a.grep_it expr end |
#with_files_from(type, expr = nil, &block) ⇒ Object
43 44 45 46 |
# File 'lib/rails3_assist/files.rb', line 43 def with_files_from type, expr=nil, &block method = "#{type}_files" send method, expr, &block if respond_to?(method) end |