Class: Raykit::SourceImport
- Inherits:
-
Hash
- Object
- Hash
- Raykit::SourceImport
- Defined in:
- lib/raykit/sourceImport.rb
Instance Method Summary collapse
- #copy ⇒ Object
- #glob ⇒ Object
-
#initialize(url, source, glob, target, commit) ⇒ SourceImport
constructor
A new instance of SourceImport.
- #remote ⇒ Object
- #source ⇒ Object
- #target ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(url, source, glob, target, commit) ⇒ SourceImport
Returns a new instance of SourceImport.
4 5 6 7 8 9 10 |
# File 'lib/raykit/sourceImport.rb', line 4 def initialize(url,source,glob,target,commit) self['remote'] = url self['source'] = source self['glob'] = glob self['target'] = target self['commit']=commit end |
Instance Method Details
#copy ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/raykit/sourceImport.rb', line 47 def copy if(target.length == 0) puts 'target has not been specified' else FileUtils.remove_dir(target) if(Dir.exist?(target)) count=0 source_names = [] work=self['remote'].work_dir Dir.chdir(work) do if(File.exist?('rakefile.rb')) cmd = Command.new('rake clean') end Dir.chdir(self.source) do source_names=Dir.glob(self['glob']) end end source_names.each{|source_name| source_file =work + "/" + self.source + "/" + source_name target_name = target + "/" + source_name target_parent = File.dirname(target_name) FileUtils.mkdir_p(target_parent) if(!Dir.exist?(target_parent)) FileUtils.copy(source_file,target_name) count += 1 } puts ' copied ' + count.to_s + ' files to ' + target end end |
#glob ⇒ Object
24 25 26 |
# File 'lib/raykit/sourceImport.rb', line 24 def glob self['glob'] end |
#remote ⇒ Object
12 13 14 |
# File 'lib/raykit/sourceImport.rb', line 12 def remote self['remote'] end |
#source ⇒ Object
16 17 18 |
# File 'lib/raykit/sourceImport.rb', line 16 def source self['source'] end |
#target ⇒ Object
20 21 22 |
# File 'lib/raykit/sourceImport.rb', line 20 def target self['target'] end |
#update ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/raykit/sourceImport.rb', line 28 def update work=self['remote'].work_dir work_parent=File.dirname(work) FileUtils.mkdir_p(work_parent) if(!Dir.exist?(work_parent)) if(Dir.exist?(work)) Dir.chdir(work) do cmd = Command.new('git pull') end else PROJECT.run("git clone #{remote} #{work}") end Dir.chdir(work) do text=`git log -n 1` scan=text.scan(/commit ([\w]+)\s/) self['commit'] = scan[0][0].to_s end end |