Module: Hayde::Utils::Files
- Included in:
- Generator
- Defined in:
- lib/hayde/file_utils.rb
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hayde/file_utils.rb', line 10 def self.included(base) # File list method adds accessor to specified attributes that behaves like FileList. # I can specify attribute and use it like FileList instance to # include and exclude files, iterate throught file collection. # # &names - names of attributes # # Example: # # class SomeClass # include Hayde::Utils::Files # # filelist_attribute :sources # end # # x = SomeClass.new # x.sources.include 'lib/**/*.rb' # x.sources.exclude 'doc/**/*' # x.each do |file| # puts file # end # def base.filelist_attribute(*names) names.each do |name| define_method "#{name}" do files = instance_variable_get("@#{name}_files") if !files files = FileList.new() instance_variable_set("@#{name}_files", files) end files end define_method "#{name}=" do |files| if files && files.class != FileList files = FileList.new(files) end instance_variable_set("@#{name}_files", files) end end end end |