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.
5 6 7 8 9 10 11 |
# File 'lib/raykit/sourceImport.rb', line 5 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
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 |
# File 'lib/raykit/sourceImport.rb', line 48 def copy if target.length.zero? 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 cmd = Command.new('rake clean') if File.exist?('rakefile.rb') Dir.chdir(source) do source_names = Dir.glob(self['glob']) end end source_names.each do |source_name| source_file = "#{work}/#{source}/#{source_name}" target_name = "#{target}/#{source_name}" target_parent = File.dirname(target_name) FileUtils.mkdir_p(target_parent) unless Dir.exist?(target_parent) FileUtils.copy(source_file, target_name) count += 1 end puts " copied #{count} files to #{target}" end end |
#glob ⇒ Object
25 26 27 |
# File 'lib/raykit/sourceImport.rb', line 25 def glob self['glob'] end |
#remote ⇒ Object
13 14 15 |
# File 'lib/raykit/sourceImport.rb', line 13 def remote self['remote'] end |
#source ⇒ Object
17 18 19 |
# File 'lib/raykit/sourceImport.rb', line 17 def source self['source'] end |
#target ⇒ Object
21 22 23 |
# File 'lib/raykit/sourceImport.rb', line 21 def target self['target'] end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raykit/sourceImport.rb', line 29 def update work = self['remote'].work_dir work_parent = File.dirname(work) FileUtils.mkdir_p(work_parent) unless 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 |