Module: Ing::Util
Instance Method Summary collapse
- #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.
- #to_class_names(str) ⇒ Object (also: #decode_class_names)
- #to_classes(str, base = ::Object) ⇒ Object
Instance Method Details
#encode_class(klass) ⇒ Object
17 18 19 |
# File 'lib/ing/util.rb', line 17 def encode_class(klass) encode_class_names(klass.to_s.split('::')) end |
#encode_class_names(list) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ing/util.rb', line 10 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
55 56 57 |
# File 'lib/ing/util.rb', line 55 def escape_globs(path) path.to_s.gsub(/[*?{}\[\]]/, '\\\\\\&') end |
#namespaced_const_get(list, base = ::Object) ⇒ Object
25 26 27 |
# File 'lib/ing/util.rb', line 25 def namespaced_const_get(list, base=::Object) list.inject(base) {|m, klass| m.const_get(klass, false)} end |
#option?(arg) ⇒ Boolean
29 30 31 |
# File 'lib/ing/util.rb', line 29 def option?(arg) !!(/^-{1,2}/ =~ arg) end |
#split_method_args(args) ⇒ Object
not used
34 35 36 37 38 39 40 |
# File 'lib/ing/util.rb', line 34 def split_method_args(args) if option?(args.first) [nil, args] else [args.first, args[1..-1]] end end |
#to_class_names(str) ⇒ Object Also known as: decode_class_names
5 6 7 |
# File 'lib/ing/util.rb', line 5 def to_class_names(str) str.split(':').map {|c| c.gsub(/(?:\A|_+)(\w)/) {$1.upcase} } end |
#to_classes(str, base = ::Object) ⇒ Object
21 22 23 |
# File 'lib/ing/util.rb', line 21 def to_classes(str, base=::Object) namespaced_const_get( to_class_names(str), base ) end |