Module: LeapCli::Path
- Defined in:
- lib/leap_cli/path.rb
Class Method Summary collapse
- .defined?(name) ⇒ Boolean
- .exists?(name, provider_dir = nil) ⇒ Boolean
-
.find_file(arg) ⇒ Object
Tries to find a file somewhere.
-
.named_path(name, provider_dir = Path.provider) ⇒ Object
Three ways of calling:.
- .node_init_script ⇒ Object
- .platform ⇒ Object
- .provider ⇒ Object
- .provider_base ⇒ Object
- .provider_templates ⇒ Object
- .relative_path(path, provider_dir = Path.provider) ⇒ Object
- .set_platform_path(platform) ⇒ Object
- .set_provider_path(provider) ⇒ Object
- .vagrant_ssh_priv_key_file ⇒ Object
- .vagrant_ssh_pub_key_file ⇒ Object
Class Method Details
.defined?(name) ⇒ Boolean
89 90 91 |
# File 'lib/leap_cli/path.rb', line 89 def self.defined?(name) Leap::Platform.paths[name] end |
.exists?(name, provider_dir = nil) ⇒ Boolean
85 86 87 |
# File 'lib/leap_cli/path.rb', line 85 def self.exists?(name, provider_dir=nil) File.exist?(named_path(name, provider_dir)) end |
.find_file(arg) ⇒ Object
Tries to find a file somewhere. Path can be a named path or a relative path.
relative paths are checked against provider/<path> provider/files/<path> provider_base/<path> provider_base/files/<path>
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/leap_cli/path.rb', line 39 def self.find_file(arg) [Path.provider, Path.provider_base].each do |base| if arg.is_a?(Symbol) || arg.is_a?(Array) named_path(arg, base).tap {|path| return path if File.exist?(path) } else File.join(base, arg).tap {|path| return path if File.exist?(path) } File.join(base, 'files', arg).tap {|path| return path if File.exist?(path) } end end return nil end |
.named_path(name, provider_dir = Path.provider) ⇒ Object
Three ways of calling:
-
named_path [:user_ssh, ‘bob’] ==> ‘users/bob/bob_ssh.pub’
-
named_path :known_hosts ==> ‘files/ssh/known_hosts’
-
named_path ‘/tmp/x’ ==> ‘/tmp/x’
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/leap_cli/path.rb', line 64 def self.named_path(name, provider_dir=Path.provider) if name.is_a? Array if name.length > 2 arg = name[1..-1] name = name[0] else name, arg = name end else arg = nil end if name.is_a? Symbol Util::assert!(Leap::Platform.paths[name], "Error, I don't know the path for :#{name} (with argument '#{arg}')") filename = eval('"' + Leap::Platform.paths[name] + '"') return provider_dir + '/' + filename else return name end end |
.node_init_script ⇒ Object
110 111 112 |
# File 'lib/leap_cli/path.rb', line 110 def self.node_init_script File.join(@platform, 'bin', 'node_init') end |
.platform ⇒ Object
5 6 7 |
# File 'lib/leap_cli/path.rb', line 5 def self.platform @platform ||= nil end |
.provider ⇒ Object
17 18 19 |
# File 'lib/leap_cli/path.rb', line 17 def self.provider @provider end |
.provider_base ⇒ Object
9 10 11 |
# File 'lib/leap_cli/path.rb', line 9 def self.provider_base "#{platform}/provider_base" end |
.provider_templates ⇒ Object
13 14 15 |
# File 'lib/leap_cli/path.rb', line 13 def self.provider_templates "#{platform}/provider_templates" end |
.relative_path(path, provider_dir = Path.provider) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/leap_cli/path.rb', line 93 def self.relative_path(path, provider_dir=Path.provider) if provider_dir path = named_path(path, provider_dir) path.sub(/^#{Regexp.escape(provider_dir)}\//,'') else path end end |
.set_platform_path(platform) ⇒ Object
24 25 26 |
# File 'lib/leap_cli/path.rb', line 24 def self.set_platform_path(platform) @platform = platform end |
.set_provider_path(provider) ⇒ Object
21 22 23 |
# File 'lib/leap_cli/path.rb', line 21 def self.set_provider_path(provider) @provider = provider end |
.vagrant_ssh_priv_key_file ⇒ Object
102 103 104 |
# File 'lib/leap_cli/path.rb', line 102 def self.vagrant_ssh_priv_key_file File.join(LEAP_CLI_BASE_DIR, 'vendor', 'vagrant_ssh_keys', 'vagrant.key') end |
.vagrant_ssh_pub_key_file ⇒ Object
106 107 108 |
# File 'lib/leap_cli/path.rb', line 106 def self.vagrant_ssh_pub_key_file File.join(LEAP_CLI_BASE_DIR, 'vendor', 'vagrant_ssh_keys', 'vagrant.pub') end |