Module: PreCommit::Utils::GitConversions

Included in:
Configuration::Providers::Git
Defined in:
lib/pre-commit/utils/git_conversions.rb

Instance Method Summary collapse

Instance Method Details

#arr2str(value) ⇒ Object



43
44
45
# File 'lib/pre-commit/utils/git_conversions.rb', line 43

def arr2str(value)
  "[#{value.map{|v| sym_symbolize(v) }.join(", ")}]"
end

#git_to_ruby(value) ⇒ Object

git_to_ruby related



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pre-commit/utils/git_conversions.rb', line 7

def git_to_ruby(value)
  value = value.chomp.strip if String === value
  case value
  when /\A\[(.*)\]\Z/
    str2arr($1)
  when ''
    nil
  when String
    str_symbolize(value)
  else
    value
  end
end

#ruby_to_git(value) ⇒ Object

ruby_to_git related



34
35
36
37
38
39
40
41
# File 'lib/pre-commit/utils/git_conversions.rb', line 34

def ruby_to_git(value)
  case value
  when Array
    arr2str(value)
  else
    sym_symbolize(value)
  end
end

#str2arr(string) ⇒ Object



21
22
23
# File 'lib/pre-commit/utils/git_conversions.rb', line 21

def str2arr(string)
  string.split(/, ?/).map{|s| str_symbolize(s.chomp.strip) }
end

#str_symbolize(string) ⇒ Object



25
26
27
28
29
30
# File 'lib/pre-commit/utils/git_conversions.rb', line 25

def str_symbolize(string)
  if string =~ /\A:(.*)\Z/
  then $1.to_sym
  else string
  end
end

#sym_symbolize(value) ⇒ Object



47
48
49
50
51
52
# File 'lib/pre-commit/utils/git_conversions.rb', line 47

def sym_symbolize(value)
  if Symbol === value
  then ":#{value}"
  else value.to_s
  end
end