Module: KubeDSL::StringHelpers

Extended by:
StringHelpers
Included in:
ArrayFieldRes, Builder, DefaultFieldRes, FieldRes, KeyValueFieldRes, ObjectFieldRes, Ref, ResourceMeta, StringHelpers
Defined in:
lib/kube-dsl/string_helpers.rb

Constant Summary collapse

RUBY_KEYWORDS =
%w(
  BEGIN END alias and begin break case class def defined? do else elsif
  end ensure false for if in module next nil not or redo rescue retry
  return self super then true undef unless until when while yield
)

Instance Method Summary collapse

Instance Method Details

#capitalize(str) ⇒ Object



9
10
11
# File 'lib/kube-dsl/string_helpers.rb', line 9

def capitalize(str)
  str.sub(/\A(.)/) { $1.upcase }
end

#underscore(str) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/kube-dsl/string_helpers.rb', line 13

def underscore(str)
  str
    .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .gsub('-', '_')
    .downcase
end

#unkeywordify(str) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/kube-dsl/string_helpers.rb', line 21

def unkeywordify(str)
  if RUBY_KEYWORDS.include?(str)
    "#{str}_field"
  else
    str
  end
end