Module: InfraRuby
- Defined in:
- lib/infraruby-base.rb
Class Method Summary collapse
- .each_library_glob(dir) ⇒ Object
- .each_library_name(dir) ⇒ Object
- .each_library_path(dir) ⇒ Object
- .gemspec_name ⇒ Object
- .if(c) ⇒ Object
- .library_paths(dir) ⇒ Object
- .load_gemspec ⇒ Object
- .load_library(dir) ⇒ Object
- .load_parent_library(dir) ⇒ Object
- .system!(command, *args) ⇒ Object
- .with_clean_env(&block) ⇒ Object
Class Method Details
.each_library_glob(dir) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/infraruby-base.rb', line 69 def each_library_glob(dir) each_library_name(dir) do |name| yield File.join(dir, "meta-", name) yield File.join(dir, "ruby", name) yield File.join(dir, "meta+", name) end return end |
.each_library_name(dir) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/infraruby-base.rb', line 52 def each_library_name(dir) path = File.join(dir, "manifest.txt") begin data = File.read(path) rescue Errno::ENOENT yield "**/*.{ir,rb}" return end data.each_line do |line| name = line.strip unless name.empty? yield name end end return end |
.each_library_path(dir) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/infraruby-base.rb', line 78 def each_library_path(dir) visited = {} each_library_glob(dir) do |glob| paths = Dir.glob(glob) paths.sort! paths.each do |path| unless visited.key?(path) visited[path] = path yield path end end end return end |
.gemspec_name ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/infraruby-base.rb', line 42 def gemspec_name spec = load_gemspec if spec.nil? return nil end return spec.name end |
.if(c) ⇒ Object
3 4 5 6 |
# File 'lib/infraruby-base.rb', line 3 def if(c) yield if c return end |
.library_paths(dir) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/infraruby-base.rb', line 93 def library_paths(dir) paths = [] each_library_path(dir) do |path| paths.push(path) end return paths end |
.load_gemspec ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/infraruby-base.rb', line 30 def load_gemspec files = Dir["*.gemspec"] case files.size when 0 return nil when 1 return Gem::Specification.load(files.first) else raise Gem::LoadError, "multiple gemspecs in current directory" end end |
.load_library(dir) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/infraruby-base.rb', line 101 def load_library(dir) each_library_path(dir) do |path| load(path) if File.exists?(path) end return end |
.load_parent_library(dir) ⇒ Object
108 109 110 111 |
# File 'lib/infraruby-base.rb', line 108 def load_parent_library(dir) load_library(File.dirname(dir)) return end |
.system!(command, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/infraruby-base.rb', line 19 def system!(command, *args) with_clean_env do success = Kernel.system(command, *args) if success.nil? raise RuntimeError, "command not found: #{command}" end return success end raise RuntimeError end |
.with_clean_env(&block) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/infraruby-base.rb', line 10 def with_clean_env(&block) if defined?(Bundler) Bundler.with_clean_env(&block) else block.call end return end |