Module: MultiGit::Tree::Builder::DSL
- Included in:
- Directory::Builder, MultiGit::Tree::Builder
- Defined in:
- lib/multi_git/tree/builder.rb
Instance Method Summary collapse
-
#changed?(path = '.') ⇒ Boolean
Checks if the file at the given path was changed.
- #clear ⇒ Object
- #delete(name) ⇒ Object
- #directory(name, &block) ⇒ Object
- #entry_set(key, value) ⇒ Object private
- #executeable(name, content = nil, &block) ⇒ Object
- #file(name, content = nil, &block) ⇒ Object
- #link(name, target) ⇒ Object
- #set(key, *args, &block) ⇒ Object (also: #[]=)
- #to_builder ⇒ self
Instance Method Details
#changed?(path = '.') ⇒ Boolean
Checks if the file at the given path was changed.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/multi_git/tree/builder.rb', line 250 def changed?( path = '.' ) begin new = traverse(path) rescue Error::EntryDoesNotExist return false unless from begin old = from.traverse(path) rescue Error::EntryDoesNotExist return false end return true end return true unless from begin old = from.traverse(path) rescue Error::EntryDoesNotExist return true end return new != old end |
#clear ⇒ Object
228 229 230 231 232 233 |
# File 'lib/multi_git/tree/builder.rb', line 228 def clear names.each do |name| delete(name) end return nil end |
#delete(name) ⇒ Object
224 225 226 |
# File 'lib/multi_git/tree/builder.rb', line 224 def delete(name) set(name){ nil } end |
#directory(name, &block) ⇒ Object
212 213 214 215 216 |
# File 'lib/multi_git/tree/builder.rb', line 212 def directory(name, &block) set(name){|parent, name| Directory::Builder.new(parent, name, &block) } end |
#entry_set(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 |
# File 'lib/multi_git/tree/builder.rb', line 148 def entry_set(key, value) dirty_entries[key] = make_entry(key, value) end |
#executeable(name, content = nil, &block) ⇒ Object
206 207 208 209 210 |
# File 'lib/multi_git/tree/builder.rb', line 206 def executeable(name, content = nil, &block) set(name){|parent, name| Executeable::Builder.new(parent, name, content, &block) } end |
#file(name, content = nil, &block) ⇒ Object
200 201 202 203 204 |
# File 'lib/multi_git/tree/builder.rb', line 200 def file(name, content = nil, &block) set(name){|parent, name| File::Builder.new(parent, name, content, &block) } end |
#link(name, target) ⇒ Object
218 219 220 221 222 |
# File 'lib/multi_git/tree/builder.rb', line 218 def link(name, target) set(name){|parent, name| Symlink::Builder.new(parent, name, target) } end |
#set(path, options = {:create => true }) {|parent, name| ... } ⇒ Object #set(path, options = {:create => true }, value) ⇒ Object Also known as: []=
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/multi_git/tree/builder.rb', line 117 def set(key, *args, &block) = {} case(args.size) when 0 raise ArgumentError, "Expected a value or a block" unless block value = block when 1 if block = args[0] value = block else value = args[0] end when 2 raise ArgumentError, "Expected either a value or a block, got both" if block = args[0] value = args[1] else raise ArgumentError, "Expected 1-3 arguments, got #{args.size}" end # okay, a bit simple here for now parts = key.split('/').reject{|k| k == '' || k == '.' } if parts.any?{|p| p == ".." } raise MultiGit::Error::InvalidTraversal, "Traversal to parent directories is currently not supported while setting." end return traverse_set( self, parts, value, .fetch(:create,true)) end |
#to_builder ⇒ self
236 237 238 |
# File 'lib/multi_git/tree/builder.rb', line 236 def to_builder self end |