Class: Vendorer
- Inherits:
-
Object
- Object
- Vendorer
- Defined in:
- lib/vendorer.rb,
lib/vendorer/version.rb
Constant Summary collapse
- VERSION =
'0.1.13'
Instance Method Summary collapse
- #file(path, url = nil) ⇒ Object
- #folder(path, url = nil, options = {}) ⇒ Object
- #from(url, options = {}) ⇒ Object
-
#init ⇒ Object
Creates Vendorfile with examples.
-
#initialize(options = {}) ⇒ Vendorer
constructor
A new instance of Vendorer.
- #parse(content) ⇒ Object
- #rewrite(path) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Vendorer
Returns a new instance of Vendorer.
5 6 7 8 |
# File 'lib/vendorer.rb', line 5 def initialize(={}) @options = @sub_path = [] end |
Instance Method Details
#file(path, url = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/vendorer.rb', line 14 def file(path, url=nil) target_path = complete_path(path) update_or_not target_path do run "mkdir -p #{File.dirname(target_path)}" if @copy_from_url copy_from_path(target_path, url || path) else run "curl '#{url}' -L --compressed -o #{target_path}" raise "Downloaded empty file" unless File.exist?(target_path) end yield target_path if block_given? end end |
#folder(path, url = nil, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendorer.rb', line 28 def folder(path, url=nil, ={}) if @copy_from_path or url target_path = complete_path(path) update_or_not target_path do run "rm -rf #{target_path}" run "mkdir -p #{File.dirname(target_path)}" if @copy_from_path copy_from_path(target_path, url || path) else download_repository(url, target_path, ) end yield target_path if block_given? end else @sub_path << path yield @sub_path.pop end end |
#from(url, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/vendorer.rb', line 66 def from(url, ={}) Dir.mktmpdir do |tmpdir| download_repository url, tmpdir, @copy_from_url, @copy_from_path = url, tmpdir yield @copy_from_url = @copy_from_path = nil end end |
#init ⇒ Object
Creates Vendorfile with examples
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vendorer.rb', line 55 def init separator = "<!-- extracted by vendorer init -->" readme = File.read(File.('../../Readme.md', __FILE__)) examples = readme.split(separator)[1] examples.gsub!(/```.*/,'') # remove ``` from readme examples = examples.split("\n").map do |l| (l.start_with? '#' or l.empty?) ? l : "# #{l}" end.join("\n") File.open('Vendorfile', 'w') { |f| f.write(examples.strip) } end |
#parse(content) ⇒ Object
10 11 12 |
# File 'lib/vendorer.rb', line 10 def parse(content) eval(content, nil, 'Vendorfile', 1) end |
#rewrite(path) ⇒ Object
48 49 50 51 52 |
# File 'lib/vendorer.rb', line 48 def rewrite(path) content = File.read(path) result = yield content File.open(path,'w'){|f| f.write(result) } end |