Class: Overapp::Files
- Includes:
- Enumerable, FromHash
- Defined in:
- lib/overapp/files.rb
Instance Method Summary collapse
- #add(ops) ⇒ Object
- #apply(on_top, ops = {}) ⇒ Object
- #apply_file(top_file, ops = {}) ⇒ Object
- #delete(path) ⇒ Object
- #each(&b) ⇒ Object
- #size ⇒ Object
- #with_tmp(&b) ⇒ Object
- #write_to!(dir) ⇒ Object
Instance Method Details
#add(ops) ⇒ Object
16 17 18 19 |
# File 'lib/overapp/files.rb', line 16 def add(ops) ops = file_class.new(:path => ops[:file], :full_body => ops[:body]) if ops.kind_of?(Hash) self.files[ops.path] = ops end |
#apply(on_top, ops = {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/overapp/files.rb', line 28 def apply(on_top,ops={}) res = self.class.new(:files => files.clone) on_top.each do |top_file| res.apply_file(top_file,ops) end res end |
#apply_file(top_file, ops = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/overapp/files.rb', line 36 def apply_file(top_file,ops={}) if ops[:vars] && ops[:vars].size > 0 top_file.vars = ops[:vars] end existing = files[top_file.path] raise MissingBaseFileError.new(:top_file => top_file, :base => self) if !existing && top_file.has_note? new_file = top_file.combined(existing) if new_file add new_file else delete top_file.path end end |
#delete(path) ⇒ Object
20 21 22 |
# File 'lib/overapp/files.rb', line 20 def delete(path) self.files.delete(path) end |
#each(&b) ⇒ Object
51 52 53 |
# File 'lib/overapp/files.rb', line 51 def each(&b) files.values.each(&b) end |
#size ⇒ Object
24 25 26 |
# File 'lib/overapp/files.rb', line 24 def size files.size end |
#with_tmp(&b) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/overapp/files.rb', line 62 def with_tmp(&b) Overapp::TmpDir.with do |dir| write_to! dir b[dir] end end |
#write_to!(dir) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/overapp/files.rb', line 55 def write_to!(dir) each do |f| f.write_to! dir end self end |