Parent

Namespace

Bones::App::FileManager

Constants

Error

Attributes

source[RW]
destination[RW]
archive[RW]
verbose[RW]

Public Class Methods

new( opts = {} ) click to toggle source
    # File lib/bones/app/file_manager.rb, line 14
14:   def initialize( opts = {} )
15:     self.source = opts[:source]
16:     self.destination = opts[:destination]
17:     self.verbose = opts[:verbose]
18: 
19:     @out = opts[:stdout] || $stdout
20:     @err = opts[:stderr] || $stderr
21:   end

Public Instance Methods

_checkout( repotype ) click to toggle source
    # File lib/bones/app/file_manager.rb, line 78
78:   def _checkout( repotype )
79:     case repotype
80:     when :git
81:       system('git', 'clone', source, destination)
82:       FileUtils.rm_rf(File.join(destination, '.git'))
83:     when :svn
84:       system('svn', 'export', source, destination)
85:     else
86:       raise Error, "Unknown repository type '#{repotype}'."
87:     end
88:   end
_cp( file ) click to toggle source

Copy a file from the Bones prototype project location to the user specified project location. A message will be displayed to the screen indicating that the file is being created.

     # File lib/bones/app/file_manager.rb, line 160
160:   def _cp( file )
161:     dir = File.dirname(file)
162:     dir = (dir == '.' ? destination : File.join(destination, dir))
163:     dst = File.join(dir,  File.basename(file))
164:     src = File.join(source, file)
165: 
166:     @out.puts(test(ee, dst) ? "updating #{dst}" : "creating #{dst}") if verbose?
167:     FileUtils.mkdir_p(dir)
168:     FileUtils.cp src, dst
169: 
170:     FileUtils.chmod(File.stat(src).mode, dst)
171:   end
_erb( name ) click to toggle source
     # File lib/bones/app/file_manager.rb, line 108
108:   def _erb( name )
109:     binding = _erb_binding(name)
110: 
111:     Dir.glob(File.join(destination, '**', '*')).each do |fn|
112:       next unless test(ff, fn) and '.bns' == File.extname(fn)
113: 
114:       txt = ERB.new(File.read(fn), nil, '-').result(binding)
115:       new_fn = fn.sub(/\.bns$/, '')
116:       File.open(new_fn, 'w') {|fd| fd.write(txt)}
117:       FileUtils.chmod(File.stat(fn).mode, new_fn)
118:       FileUtils.rm_f(fn)
119:     end
120:     self
121:   end
_erb_binding( name ) click to toggle source
     # File lib/bones/app/file_manager.rb, line 125
125:   def _erb_binding( name )
126:     obj = Object.new
127:     class << obj
128:       alias :__binding__ :binding
129:       instance_methods.each {|m| undef_method m unless m[/^(__|object_id)/]}
130:       def binding(name)
131:         classname = name.tr('-','_').split('_').map {|x| x.capitalize}.join
132:         __binding__
133:       end
134:     end
135:     obj.binding name
136:   end
_files_to_copy() click to toggle source

Returns a list of the files to copy from the source directory to the destination directory.

     # File lib/bones/app/file_manager.rb, line 141
141:   def _files_to_copy
142:     rgxp = /\A#{source}\/?/
143:     exclude = /tmp$|bak$|~$|CVS|\.svn/
144: 
145:     ary = Dir.glob(File.join(source, '**', '*'), File::FNM_DOTMATCH).map do |filename|
146:       next if exclude =~ filename
147:       next if test(dd, filename)
148:       filename.sub rgxp, ''
149:     end
150: 
151:     ary.compact!
152:     ary.sort!
153:     ary
154:   end
_rename( filename, name ) click to toggle source
     # File lib/bones/app/file_manager.rb, line 92
 92:   def _rename( filename, name )
 93:     newname = filename.gsub(/NAME/, name)
 94: 
 95:     if filename != newname
 96:       raise "cannot rename '#{filename}' to '#{newname}' - file already exists" if test(ee, newname)
 97:       FileUtils.mv(filename, newname)
 98:     end
 99: 
100:     if test(dd, newname)
101:       Dir.glob(File.join(newname, '*')).each {|fn| _rename(fn, name)}
102:     end
103:     newname
104:   end
archive_destination() click to toggle source
    # File lib/bones/app/file_manager.rb, line 45
45:   def archive_destination
46:     return false unless test(ee, destination)
47: 
48:     @out.puts "archiving #{destination}" if verbose?
49:     FileUtils.rm_rf(archive)
50:     FileUtils.mv(destination, archive)
51:     true
52:   end
copy() click to toggle source
    # File lib/bones/app/file_manager.rb, line 56
56:   def copy
57:     if repository?
58:       _checkout(repository)
59:     else
60:       _files_to_copy.each {|fn| _cp(fn)}
61:     end
62:   end
destination=( str ) click to toggle source

Sets the destination where files will be copied to. At the same time an archive directory is configured. This is simply the destination directory with a ’.archive’ extension.

    # File lib/bones/app/file_manager.rb, line 27
27:   def destination=( str )
28:     @destination = str
29:     @archive = str + '.archive' if str
30:   end
finalize( name ) click to toggle source
    # File lib/bones/app/file_manager.rb, line 66
66:   def finalize( name )
67:     name = name.to_s
68:     return if name.empty?
69: 
70:     self.destination = _rename(destination, name)
71:     _erb(name)
72: 
73:     self
74:   end
repository() click to toggle source

If the source is a repository this method returns the type of repository. This will be :git for Git repositories and :svn for Subversion repositories. Otherwise, nil is returned.

    # File lib/bones/app/file_manager.rb, line 36
36:   def repository
37:     return :git if source =~ /\.git\/?$/
38:     return :svn if source =~ /^(svn(\+ssh)?|https?|file):\/\//
39:     nil
40:   end
Also aliased as: repository?
repository?() click to toggle source
Alias for: repository

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.