Module: Ing::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/ing/util.rb

Instance Method Summary collapse

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

Returns:

  • (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