Sha256: acea63fd15f9ad19ea0806ff17553c38e3af8c7d9cb9bba1e19cc38152545eae

Contents?: true

Size: 1.02 KB

Versions: 25

Compression:

Stored size: 1.02 KB

Contents

module PreCommit
  module Utils
    module GitConversions

    # git_to_ruby related

      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

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

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

    # ruby_to_git related

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

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

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

    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pre-commit-0.32.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.31.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.30.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.29.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.28.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.27.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.26.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.25.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.24.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.23.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.22.1 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.22.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.21.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.20.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.19.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.18.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.17.0 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.16.3 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.16.2 lib/pre-commit/utils/git_conversions.rb
pre-commit-0.16.1 lib/pre-commit/utils/git_conversions.rb