Module: Ing::Util
Instance Method Summary collapse
- #decode_class(str, base = ::Object) ⇒ Object
- #decode_class_names(str) ⇒ Object
- #encode_class(klass) ⇒ Object
- #encode_class_names(list) ⇒ Object
-
#escape_globs(path) ⇒ Object
Returns a string that has had any glob characters escaped.
- #namespaced_const_get(list, base = ::Object) ⇒ Object
- #option?(arg) ⇒ Boolean
-
#split_method_args(args) ⇒ Object
not used.
Instance Method Details
#decode_class(str, base = ::Object) ⇒ Object
5 6 7 |
# File 'lib/ing/util.rb', line 5 def decode_class(str, base=::Object) namespaced_const_get( decode_class_names(str), base ) end |
#decode_class_names(str) ⇒ Object
9 10 11 |
# File 'lib/ing/util.rb', line 9 def decode_class_names(str) str.split(':').map {|c| c.gsub(/(?:\A|_+)(\w)/) {$1.upcase} } end |
#encode_class(klass) ⇒ Object
13 14 15 |
# File 'lib/ing/util.rb', line 13 def encode_class(klass) encode_class_names(klass.to_s.split('::')) end |
#encode_class_names(list) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/ing/util.rb', line 17 def encode_class_names(list) list.map {|c| c.to_s.gsub(/([A-Z])/) { ($`.empty? ? "" : "_") + $1.downcase } }.join(':') end |
#escape_globs(path) ⇒ Object
Returns a string that has had any glob characters escaped. The glob characters are ‘* ? { } [ ]`.
Examples
Util.escape_globs('[apps]') # => '\[apps\]'
Parameters
String
Returns
String
54 55 56 |
# File 'lib/ing/util.rb', line 54 def escape_globs(path) path.to_s.gsub(/[*?{}\[\]]/, '\\\\\\&') end |
#namespaced_const_get(list, base = ::Object) ⇒ Object
24 25 26 |
# File 'lib/ing/util.rb', line 24 def namespaced_const_get(list, base=::Object) list.inject(base) {|m, klass| m.const_get(klass, false)} end |
#option?(arg) ⇒ Boolean
28 29 30 |
# File 'lib/ing/util.rb', line 28 def option?(arg) !!(/^-{1,2}/ =~ arg) end |
#split_method_args(args) ⇒ Object
not used
33 34 35 36 37 38 39 |
# File 'lib/ing/util.rb', line 33 def split_method_args(args) if option?(args.first) [nil, args] else [args.first, args[1..-1]] end end |