Class: Vendorer
- Inherits:
-
Object
- Object
- Vendorer
- Defined in:
- lib/vendorer.rb,
lib/vendorer/version.rb
Constant Summary collapse
- VERSION =
'0.2.0'
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.
6 7 8 9 |
# File 'lib/vendorer.rb', line 6 def initialize(={}) @options = @sub_path = [] end |
Instance Method Details
#file(path, url = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vendorer.rb', line 15 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, "--fail", "-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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vendorer.rb', line 29 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
67 68 69 70 71 72 73 74 |
# File 'lib/vendorer.rb', line 67 def from(url, ={}) Dir.mktmpdir do |tmpdir| download_repository url, tmpdir, @copy_from_url, @copy_from_path = url, tmpdir yield(@copy_from_path) @copy_from_url = @copy_from_path = nil end end |
#init ⇒ Object
Creates Vendorfile with examples
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vendorer.rb', line 56 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
11 12 13 |
# File 'lib/vendorer.rb', line 11 def parse(content) eval(content, nil, 'Vendorfile', 1) end |
#rewrite(path) ⇒ Object
49 50 51 52 53 |
# File 'lib/vendorer.rb', line 49 def rewrite(path) content = File.read(path) result = yield content File.open(path,'w'){|f| f.write(result) } end |