Module: Envo::ValBuilder
Instance Method Summary collapse
- #from_env_string(str, host) ⇒ Object
- #from_user_string(str, host) ⇒ Object
- #from_user_text(text, host) ⇒ Object
Instance Method Details
#from_env_string(str, host) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/envo/val/val_builder.rb', line 7 def from_env_string(str, host) return NoVal.new if !str is_list = host.shell.likely_list?(str) is_path = host.shell.likely_abs_path?(str) if is_list ar = host.shell.list_to_ar(str) if is_path return PathListVal.new(host, ar) else return ListVal.new(ar) end elsif is_path return PathVal.new(host, str) else return StringVal.new(str) end end |
#from_user_string(str, host) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/envo/val/val_builder.rb', line 27 def from_user_string(str, host) if host.shell.likely_abs_path?(str) return PathVal.new(host, host.shell.fix_path(str)) end if host.shell.likely_rel_path?(str) # the pathname approach is not multi-platform # ie windows paths won't work on non-windows host # we should reimplement pathname joins for windows for this to work path = Pathname.new host.pwd path += str return PathVal.new(host, host.shell.fix_path(path.cleanpath.to_s)) end return StringVal.new str end |
#from_user_text(text, host) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/envo/val/val_builder.rb', line 44 def from_user_text(text, host) return from_user_string(text, host) if text.class != Array return NoVal.new if text.empty? elems = text.map { |str| from_user_string(str, host) } # array of 1 is as good as nothing return elems[0] if elems.size == 1 is_path = elems[0].type == :path elems.map! { |elem| elem.to_s } return is_path ? PathListVal.new(host, elems) : ListVal.new(elems) end |