Module: C3DCI::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/c3-dci/helpers.rb

Instance Method Summary collapse

Instance Method Details

#camelize!(literal) ⇒ Object



7
8
9
10
11
12
# File 'lib/c3-dci/helpers.rb', line 7

def camelize! literal
  literal.to_s.
    sub(/^(.)/){$1.upcase}.
    gsub(/[_](.)/){$1.upcase}.
    gsub(/(\/|::)(.)/){'::'+$2.upcase}
end

#constantize!(literal) ⇒ Object



14
15
16
17
18
19
# File 'lib/c3-dci/helpers.rb', line 14

def constantize! literal
  pieces = literal.to_s.split('::')
  pieces.inject(Object) do |parent, child|
    parent = parent.const_get(child)
  end
end

#objectify!(literal) ⇒ Object



21
22
23
# File 'lib/c3-dci/helpers.rb', line 21

def objectify! literal
  constantize! camelize! literal
end

#rolefy!(literal) ⇒ Object



25
26
27
28
# File 'lib/c3-dci/helpers.rb', line 25

def rolefy! literal
  type = camelize!(literal)
  constantize!(type.include?("Role") ? type : type + "Role")
end