Class: Raykit::SourceImport

Inherits:
Hash
  • Object
show all
Defined in:
lib/raykit/sourceImport.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ SourceImport

attr_accessor :remote attr_accessor :glob attr_accessor :target attr_accessor :commit



9
10
11
12
13
14
# File 'lib/raykit/sourceImport.rb', line 9

def initialize(url)
    self['remote'] = url
    self['glob'] = '**/*.cs'
    self['target'] = ''
    self['commit']=''
end

Instance Method Details

#copyObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/raykit/sourceImport.rb', line 43

def copy
    if(target.length == 0)
        puts 'target has not been specified'
    else
        count=0
        source_names = []
        work=self['remote'].work_dir
        Dir.chdir(work) do
            source_names=Dir.glob(self['glob'])
        end
        source_names.each{|source_name|
            source=work + "/" + 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,target_name)
            count += 1
        }
        puts '        copied ' + count.to_s + ' files to ' + target
    end
end

#remoteObject



16
17
18
# File 'lib/raykit/sourceImport.rb', line 16

def remote
    self['remote']
end

#targetObject



20
21
22
# File 'lib/raykit/sourceImport.rb', line 20

def target
    self['target']
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/raykit/sourceImport.rb', line 24

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
            PROJECT.run("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