Class: Vendorer

Inherits:
Object
  • Object
show all
Defined in:
lib/vendorer.rb,
lib/vendorer/version.rb

Constant Summary collapse

VERSION =
'0.1.8'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Vendorer

Returns a new instance of Vendorer.



4
5
6
7
# File 'lib/vendorer.rb', line 4

def initialize(options={})
  @options = options
  @sub_path = []
end

Instance Method Details

#file(path, url) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/vendorer.rb', line 13

def file(path, url)
  path = complete_path(path)
  update_or_not path do
    run "mkdir -p #{File.dirname(path)}"
    run "curl '#{url}' -L -o #{path}"
    raise "Downloaded empty file" unless File.exist?(path)
    yield path if block_given?
  end
end

#folder(path, url = nil, options = {}) ⇒ Object



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

def folder(path, url=nil, options={})
  if url
    path = complete_path(path)
    update_or_not path do
      run "rm -rf #{path}"
      run "mkdir -p #{File.dirname(path)}"
      run "git clone '#{url}' #{path}"
      if commit = (options[:ref] || options[:tag] || options[:branch])
        run "cd #{path} && git checkout '#{commit}'"
      end
      run("cd #{path} && git submodule update --init --recursive")
      run "rm -rf #{path}/.git"
      yield path if block_given?
    end
  else
    @sub_path << path
    yield
    @sub_path.pop
  end
end

#parse(content) ⇒ Object



9
10
11
# File 'lib/vendorer.rb', line 9

def parse(content)
  eval(content)
end

#rewrite(path) ⇒ Object



44
45
46
47
48
# File 'lib/vendorer.rb', line 44

def rewrite(path)
  content = File.read(path)
  result = yield content
  File.open(path,'w'){|f| f.write(result) }
end